Tag­ging files in Ter­mi­nal

How can I add tags to files by us­ing Ter­mi­nal com­mands?

Mac|Life - - ASK -

Ac­cess to tags in Ter­mi­nal can be dif­fi­cult be­cause they’re ac­tu­ally stored in files’ ex­tended at­tributes. You can set one stan­dard col­ored tag in the com.ap­ple. Fin­derInfo at­tribute.

In or­der to set mul­ti­ple or cus­tom tags on a file, you need to ac­cess com.ap­ple.meta­data :_kMDItemUserTags in­stead. This is the ex­tended at­tribute that Ap­ple ex­poses most to the user (in Fin­der), but there is no con­ve­nient ac­cess to it in Ter­mi­nal. The built-in com­mand xattr, for dis­play­ing and ma­nip­u­lat­ing ex­tended at­tributes, is made more dif­fi­cult to use be­cause tags are stored in a bi­nary for­mat, which is hard to han­dle out­side a pro­gram­ming lan­guage like Swift or Python.

A third-party com­mand named tag is avail­able via Home­brew, MacPorts, or from

github.com/jd­berry/tag. This should make your task a lot sim­pler and more flex­i­ble. There’s more info at bit.ly/ecx­attr via The Eclec­tic Light Com­pany web­site, but bear in mind that it gets quite tech­ni­cal.

Tags are easy to add to files in Fin­der, but they’re tougher to han­dle in Ter­mi­nal.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.