blog advertising is good for you


blog advertising is good for you
User login

Changing File Labels Outside The Finder

rexroof asks:

Question

How do a figure out if a file has a color label on it (and what it is) in a perl script? Any applescript or shell program to do it would be awesome.

Answer

I’m not really sure if there’s a perly way to do this. I don’t see anything in File::Spec::Mac or Mac::Files that appears to handle reading or changing labels. It can be done with AppleScript, though.

Try this little snippet. As is, it only works with files, not folders, but a little digging in the Finder’s dictionary should make it obvious how to use this with other filetypes.


tell application “Finder” — get the currently selected label set the_label to the label index of POSIX file “/path/to/file”

— set the label set label index of POSIX file “/path/to/file” to 0 — or to 1, or to 2, etc end tell
Average rating
(0 votes)
About JC
JC's picture

Author Biography

JC is a former Mac Genius and Mac-centric IT worker with a background in print advertising. He earned a reputation as a miracle worker when he saved the day at a new business pitch with the arcane knowledge that Apple’s ADB cables were nothing more than poorly shielded S-Video cables.

JC runs the Heroic Efforts Data Recovery Service and writes Ungenius, a tawdry tale of the life and times of a former Mac Genius.

You can contact JC via IM or via the contact form.

perhaps when appscript is ported to perl, this will half to do.

why would appscript need to be ported to perl if Mac::Glue already exists?

If perl can run Unix commands, you can get the kMDItemFSLabel attribute with mdls. Note that the Spotlight index is different than the AppleScript index:

           Spotlight       AS
none:      0                0
red:       6                2
orange:    7                1
yellow:    5                3
green:     2                6
blue:      4                4
purple:    3                5
grey:      1                7
Post new comment
The content of this field is kept private and will not be shown publicly.
10 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.