|
|
getting and setting command-line Finder color labels, xattr
|
|
|
|
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Mar 2004
Status:
Offline
|
|
Originally Posted by Since EBCDIC
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-
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Sep 2000
Location: San Francisco
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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'."
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
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).
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Mar 2004
Status:
Offline
|
|
Originally Posted by P
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-
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Dec 2000
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|