Is it possible to create some script to show all the finder-tagged items in terminal/shell?

I'd like to create something like this:

ls-tag "Music" to display all the items of Music tag


No script is needed to accomplish that. Simply use mdfind 'kMDItemUserTags=<tag>'to find all items with the tag <tag>.

In your case that's mdfind 'kMDItemUserTags=Music'.

If you want to restrict the search to a special directory use:

mdfind 'kMDItemUserTags=Music' -onlyin /path/to/folder


mdfind 'kMDItemUserTags=Music' -onlyin ~/Music/Classical\ Music/Сергей\ Сергеевич\ Прокофьев
  • than you so much! my productivity will rise ) – Pavel Sep 16 '16 at 13:28

There is a commandline tool called tag:

tag is a command line tool to manipulate tags on Mac OS X files (10.9 Mavericks and above), and to query for files with those tags. tag can use the file system's built-in metadata search functionality to rapidly find all files that have been tagged with a given set of tags.

Its help page:

tag - A tool for manipulating and querying file tags.
    tag -a | --add <tags> <path>...     Add tags to file
    tag -r | --remove <tags> <path>...  Remove tags from file
    tag -s | --set <tags> <path>...     Set tags on file
    tag -m | --match <tags> <path>...   Display files with matching tags
    tag -l | --list <path>...           List the tags on file
    tag -f | --find <tags> <path>...    Find all files with tags, limited to paths if present
  <tags> is a comma-separated list of tag names; use * to match/find any tag.
  additional options:
        -v | --version      Display version
        -h | --help         Display this help
        -A | --all          Display invisible files while enumerating
        -e | --enter        Enter/enumerate directories provided
        -d | --descend      Recursively descend into directories
        -n | --name         Turn on filename display in output (default)
        -N | --no-name      Turn off filename display in output (list, find, match)
        -t | --tags         Turn on tags display in output (find, match)
        -T | --no-tags      Turn off tags display in output (list)
        -g | --garrulous    Display tags each on own line (list, find, match)
        -G | --no-garrulous Display tags comma-separated after filename (default)
        -H | --home         Find tagged files in user home directory
        -L | --local        Find tagged files in home + local filesystems
        -R | --network      Find tagged files in home + local + network filesystems
        -0 | --nul          Terminate lines with NUL (\0) for use with xargs -0

Available at https://github.com/jdberry/tag/ or via Macports or Homebrew

  • Can the average Mac user get this working? If so, how? Looking at the github page it seems like I would need to be a developer using xcode or something in order to build it. – Max Well Jul 3 '20 at 14:57
  • Yes, there's prebuilt packages, & Building and Installing is easy to do. – PeterVP Jul 4 '20 at 10:09

You must log in to answer this question.

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