6

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.

1

5 Answers 5

5

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

5
  • Hmmm... even if I used awk the result was clumsy, as I got something like ` "mytag_Tag_ViewSettings" = {, where mytag` is what I'm looking for. Thus I think it's much easier to just open Finder and navigate toward the tag bar. Thanks for your answer though.
    – Blaszard
    Dec 1, 2013 at 14:27
  • I updated my parsing part, it now returns only the name :) Dec 1, 2013 at 17:09
  • 2
    Everybody should look at @TedWise answer below, it explains why the list obtained through this method is not complete. Oct 1, 2014 at 18:11
  • FYI: With OS X El Capitan, the equivalent command is, defaults read com.apple.finder.plist FavoriteTagNames. However, that list doesn't include custom tag names. Jul 31, 2016 at 17:53
  • 2
    This shouldn't be the answer. It just doesn't work at all. It doesn't show my custom tags.
    – sgon00
    Aug 29, 2018 at 14:51
6

You can also use tag:

tag -tgf \*|grep '^    '|cut -c5-|sort -u

tag -f \* finds all files with tags, -t includes tag names in the output, and -g prints each tag on a separate line.

2
  • No mention of OpenMeta in the opening question, but it's worth noting that the current version of tag does not list OpenMeta tags on Mavericks. github.com/jdberry/tag/issues/17 is 'Add limited support for OpenMeta'. Jul 26, 2015 at 22:00
  • This should be the accepted answer, only this creates a complete tag list here.
    – lejonet
    Sep 7, 2019 at 19:45
4

That list isn't comprehensive. It's only tags added through Finder. There's an additional file ~/Library/SyncedPreferences/com.apple.finder.plist, that also lists the tags that have been manipulated in Finder.

If you tagged a file in Terminal or using another tool and never manipulated the tags in Finder, then the tags won't be in either list.

1
  • 1
    I tagged a file with the Tag app that others mentioned. The tag then appears in the Finder > Preferences > Tags list, so it must be stored somewhere, though. Do we know where it's stored?
    – Gary
    Apr 28, 2018 at 6:24
3

You can also use mdfind in combination with mdls to get the same result:

/usr/bin/mdfind -0 "(kMDItemUserTags == '*')" |xargs -0 mdls -name kMDItemUserTags |grep '^    ' |cut -c5- |cut -d , -f 1 |sort -u

Would be interesting to benchmark, which one is faster.

2

Colour followed by path:

/usr/bin/mdfind -0 "(kMDItemUserTags == '*')" | xargs -I % sh -c 'echo $(mdls -name kMDItemUserTags % | grep "^ " |cut -c5-) %'

1
  • I get error xargs: unterminated quote Nov 18, 2020 at 11:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .