MacOS – List all tags in Terminal in Mavericks

finder-tagmacosterminal

Is it feasible to list all tags already defined in OS X in Terminal?

I know there are some third-party applications that list all tags, but I just want to use Terminal to find all tags, since I use this tool to work with tags in Terminal (but unfortunately the tool doesn't provide to list tags for an entire system – it just lists for a single or multiple files selected arbitrarily).

Thanks.

Best Answer

The tags name are in ~/Library/Preferences/com.apple.finder.list.

You can read it with

defaults read com.apple.finder.plist ViewSettingsDictionary

It will need some parsing to be a bit clearer :

defaults read com.apple.finder.plist ViewSettingsDictionary | 
    awk 'NR%12==2'| grep -o '".*"' |  sed 's/^.\(.*\).\{18\}$/\1/'

Other possibility is parsing the plist as xml. To do that you'll need to first convert the plist from binary to xml using.

plutil -convert xml1 ~/Library/Preferences/com.apple.finder.plist