App that does not support Smart Folders / Tags – how to access Tags/Smart Folders via Terminal or elsewhere

finderfinder-tagsmart-foldersterminal

I am attempting to start organising my .WAV/.AIFF samples by using Tags. Unfortunately the app I want to use them in, does not support Tags. I'd like to spend a few days setting up my 100gb+ sample archive using Tags, and then somehow figure out a way of showing them using the app that doesn't support Tags.

So far I've tried to look at the Finder Status Bar, while in a Tag "folder" to see if there's a path I could paste into the Terminal, and then open up – i.e., a "physical" location for the Tag "Folder". I haven't figured out how. The app that doesn't support Tags does have a way of going into even hidden folders, just by selecting "Go To Folder".

But I'm not sure how to use that knowledge to then dig up where I should inform the app to go.

I've just created a Smart Folder that only shows files Tagged with that specific Tag. However, this seems to be a file with the extension .savedSearch – so I'm not sure how to access that "folder" via the Terminal, figure out it's path and paste that onto the App that doesn't support Tags or Smart Folders.

Also, if I drag a Tag to the Terminal, it will show up as a .savedSearch too, but unfortunately I cannot access that either.

So, how do I organise my files using Tags so that I can access them on apps that have no support for Tags? I don't want to physically move the files around as that will take me months and months to do, time is limited as it is already.

Edit: Nope, I don't want to create tags or smart folders using Terminal, just access them just like if it were a regular folder.

Best Answer

What you could do is running a script which uses mdfind to symlink all files with a specific tag into a folder, and then access the files via this folder.

cd TAG_FOLDER
mdfind -0 kMDItemUserTags="Red" | xargs -0 -n 1 -J % ln -s % .

(Replace "Red" with the name of the tag you are looking for)

If several tagged files have the same name only the first one will get linked (you'll get a warning message for the others). And, of course, the commands needs to be rerun every time you add/remove the tag from a file.

PS: There is a small caveat here. Not all applications handle symlinked files the same way. Test first whether an application writes a changed file back to the original place or just replaces the symlink with the updated version.

PPS:

  • mdfind -0 finds all files/folders matching the query (in this case the tag). The -0 ensures that the string passed to the next command is terminated by an ASCII NUL character (to ensure that file names containing spaces etc get handled correctly)
  • xargs -0 -n 1 -J % reads one line of input to build and execute a command. -J % sets the placeholder for the input line to %
  • ln -s % . symlinks the file/folder in % into the current directory (.)