Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > getting and setting command-line Finder color labels, xattr

getting and setting command-line Finder color labels, xattr
Thread Tools
Since EBCDIC
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 24, 2009, 10:28 AM
 
I want to post-process files pulled from a camera, setting the file label to (say) green for images and red for video. I want to do this from the command line, not AppleScript. The xattr command shows the tenth byte to contain the Finder's label color code:

Code:
% xattr -l label* label_green: com.apple.FinderInfo: 0000 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 ................ 0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ label_red: com.apple.FinderInfo: 0000 00 00 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 ................ 0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ %
but I can't find any shorthand to get and set just the color code. The -h help isn't much help, and I can't believe there isn't a simple way to specify the extended attributes to xattr.

What documentation have I overlooked? Sigh. Many thanks.
Since EBCDIC
Using Macs since they were Lisas.
     
Hal Itosis
Grizzled Veteran
Join Date: Mar 2004
Status: Offline
Reply With Quote
May 24, 2009, 11:09 AM
 
Originally Posted by Since EBCDIC View Post
I want to do this from the command line, not AppleScript.
Does that mean you won't consider using /usr/bin/osascript either?

E.g.,
Code:
/usr/bin/osascript <<-HereDoc tell application "Finder" -- Here we can put typical -- AppleScript statements -- inside a shell script. end tell HereDoc
That's probably easier than trying to tinker with xattr -w 'com.apple.FinderInfo' "data"
-HI-
     
Since EBCDIC  (op)
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 25, 2009, 02:59 AM
 
Yes, it really means I want to use canonical UNIX-style commands. Sadly this doesn't seem to have been well-documented (or, if one is snarky, documented at all). It blows me away that Apple has added this metadata and half-heartedly shared it with the world. It's such a poor job of what could have been done well, something a summer intern could complete in a few months. And there's such a legacy of adding to UNIX that I'm seriously bummed.

I don't *want* to reinvent the wheel, but it does seem necessary. I'm wondering whether I can cobble something together which meets the Darwin submission requirements. Sigh.
Since EBCDIC
Using Macs since they were Lisas.
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
May 25, 2009, 06:49 AM
 
There is, or was, a third-party package called osxutils that did this, but it doesn't seem to have been updated recently.

Apple's handling of labels was always an afterthought - they were only ever added to shut up some of us OS9 converts, not because they fit into the grand scheme of OS X file management - so it's not surprising that Apple never added CLI utilities for setting them.
The new Mac Pro has up to 30 MB of cache inside the processor itself. That's more than the HD in my first Mac. Somehow I'm still running out of space.
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 25, 2009, 02:18 PM
 
IIRC, you can't even set the Finder label through the standard Mac programming interfaces. It's supposed to be a private Finder thing, I think.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
May 25, 2009, 03:03 PM
 
I don't have my Mac with me to test this, but I think you can do it with FSSetCatalogInfo with kFSCatInfoFinderInfo as the 'whichInfo' argument, and the label you want (an integer from 0 to 7) in the appropriate bits of the 'finderFlags' field of the FileInfo structure.

If what you're trying to do is make a tool to submit to the Darwin source, you probably want to write in C anyway, so this is the way you'd want to go about doing it. The only question is whether pure Darwin supports the FSSetCatalogInfo call or not, which I'm not sure about (but which you can check pretty easily if you've got a Darwin disk).

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
Hal Itosis
Grizzled Veteran
Join Date: Mar 2004
Status: Offline
Reply With Quote
May 25, 2009, 05:41 PM
 
Originally Posted by P View Post
There is, or was, a third-party package called osxutils that did this, but it doesn't seem to have been updated recently.
Just tried setlabel. It's a ppc binary, but it worked fine (MBP here).
And the page you posted there also has a link to the source code, so...
-HI-
     
CharlesS
Posting Junkie
Join Date: Dec 2000
Status: Offline
Reply With Quote
May 25, 2009, 09:19 PM
 
I checked the source code, and they're indeed just setting the three bits in finderFlags masked by the kColor constant, as I suspected. However, they're using a number of deprecated APIs and some kind of weird logic (they use like 33 lines to clear the labels to 0, which they could have done easily enough by &=ing it with ~kColor), so I'd just recommend following Apple's File System docs, as this is an extremely simple operation.

File Manager Reference

Ticking sound coming from a .pkg package? Don't let the .bom go off! Inspect it first with Pacifist. Macworld - five mice!
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:25 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,