Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Script that reads OpenMeta tags and writes them to OS X Mavericks tags. This requires a OpenMeta binary to be installed. Change its path, if you prefer it to be somewhere else. For the files to be processed properly don't include a trailing slash in `$files…
# =============================================================
# = OpenMeta to OS X Tags =
# =============================================================
# Script to convert OpenMeta tags to OS X Mavericks tags.
# Created by Zettt (Andreas Zeitler) on 2013-06-28
# Source,
# OpenMeta to OS X Tags by Andreas Zeitler is licensed under a
# Creative Commons Attribution-NonCommercial-ShareAlike
# 3.0 Unported License.
# Based on a work at
# Permissions beyond the scope of this license may be
# available at
# =============================================================
# with lots of help from various sources such as stack overflow
# Thanks!
# =============================================================
# Please run:
# chmod +x
# Call the script using:
# ./
# this is the absolute path of the directory you want to process
# please no trailing slash!
# think twice if it's really necessary to process your entire $HOME
unset a i
while IFS= read -r -d $'\0' file; do
done < <(find "$files" -print0)
# echo ${fileArray[@]}
set a i
# this is the plist part that will go before and end of tags
plistFront='<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""><plist version="1.0"><array>'
for currentFile in "${fileArray[@]}"; do
echo "Processing: $currentFile"
# extract openmeta tags to string
currentTags=$(/usr/local/bin/openmeta -t -p "$currentFile")
# remove trailing -p path from openmeta
currentTags=$(echo ${currentTags%%$currentFile})
# remove trailing whitespace (if any)
currentTags=$(echo ${currentTags%%\w})
# only process if there are tags
if [[ -z $currentTags ]]; then
echo "File has no tags."
echo "Number of tags: ${#tagArray[@]}"
echo "Tags: $currentTags"
# create array of all tags
eval tagArray=($currentTags)
# assemble plist string of tags
for i in "${tagArray[@]}"; do
# echo "Tag $i"
# write tags to file
xattr -w "$plistFront$plistTagString$plistEnd" "$currentFile"
# Reading OpenMeta tags:
# xattr -p | xxd -r -p | plutil -convert xml1 -o - - | xmllint --xpath "/plist/array/string/text()" -
# Writing Mavericks tags
# xattr -w '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""><plist version="1.0"><array><string>tag1</string><string>tag2</string></array></plist>' $currentFile

I get this error when I try to run the script:

./ line 41: syntax error near unexpected token<'./ line 41: done < <(find "$files" -print0)'

lowski commented Jan 24, 2016

@nickbloom replace 39-41 lines with:

while read -r file; do
done <<< "`find $files`"

lowski commented Jan 24, 2016

This script doesn't work correctly - if you update tags inside nvAlt app after your tags has already been converted, os x tags won't be updated.

I've updated the script here. It also doesn't require openmeta binary any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment