Script to copy XnView base tags to Mac OS X Finder tags

Ask for help and post your question on how to use XnView MP.

Moderators: XnTriq, xnview

Post Reply
danjcla
Posts: 49
Joined: Fri Feb 13, 2015 12:08 am

Script to copy XnView base tags to Mac OS X Finder tags

Post by danjcla » Mon Jan 18, 2016 8:29 pm

Hi thought I'd post this in case others might find it useful.

Ugly copy of base XnViewMP categories (the 5 color tags and 5 ratings tags aka Rating and Colour Label) to Mac Finder tags.

It'd be pretty easy to also do other tags, and also do the hackish back-to-XnViewMP tags I did with the fake features (see my sig below). Also not all that hard to sync instead of just add. Not sure what if any limits there are on the number and text length of Mac OS X tags.

Need to have mac homebrew installed, and via it "tag" and "sqlite3".

Code: Select all

#!/bin/bash

# One way copy of XnViewMP rating and colour label to Mac OS X Finder tags.
# Running multiple times is fine but will never remove a finder tag.

# You may need to relaunch finder (option-right-click on dock icon)
# in order to see the changes immediatly.

# You can't change the colors of tags using the command line tool tag,
# but you can do it manually and it'll stay that way.

cat > ratings.sql << EOF
SELECT Pathname || Filename, Rating
FROM Images
JOIN Folders on Folders.FolderID = Images.FolderID
WHERE Rating > 0
ORDER BY Pathname || Filename;
EOF

cat > colors.sql << EOF
SELECT Pathname || Filename, Color
FROM Images
JOIN Folders on Folders.FolderID = Images.FolderID
WHERE Color > 0
ORDER BY Pathname || Filename;
EOF

sqlite3 ~/.xnviewmp/XnView.db < ratings.sql > ratings.txt
sqlite3 ~/.xnviewmp/XnView.db < colors.sql > colors.txt

echo
echo "NOW PROCESSING RATINGS"
echo

while read LINE; do
FILE="$(echo $LINE | sed '$s/\(.\{2\}\)$//')"
RATING="$(echo $LINE | sed 's/.*\(.\)/\1/')"
test -f "$FILE" || RATING="0"
case $RATING in
1)
tag --add xn1poor "$FILE"
;;
2)
tag --add xn2fair "$FILE"
;;
3)
tag --add xn3average "$FILE"
;;
4)
tag --add xn4good "$FILE"
;;
5)
tag --add xn5excellent "$FILE"
;;
*)
false
;;
esac
done < ratings.txt

echo
echo "NOW PROCESSING COLORS"
echo

while read LINE; do
FILE="$(echo $LINE | sed '$s/\(.\{2\}\)$//')"
COLOR="$(echo $LINE | sed 's/.*\(.\)/\1/')"
test -f "$FILE" || COLOR="0"
case $COLOR in
1)
tag --add xnImportant "$FILE"
;;
2)
tag --add xnWork "$FILE"
;;
3)
tag --add xnPersonal "$FILE"
;;
4)
tag --add xnTodo "$FILE"
;;
5)
tag --add xnLater "$FILE"
;;
*)
false
;;
esac
done < colors.txt

Post Reply