The kMDItemFSLabel attribute is a Finder property. You need to use the way to communicate with Finder to change its data. As far as I know, there is no bit with which you can twist Perl to change Finder data without wading through Finder.
There are several ways to do this:
Use CamelBones when a new version comes out. This allows you to use the bridge from Objective-C from Perl. Then you will need to use the Apple method with Cocoa system calls. A steep learning curve for Cocoa ...
If you have developer tools, use / Developer / Tools / SetFile (if this supports the metadata element)
Use osascript to send a Finder message to change the color of the file. You can see this earlier SO post for tips on this.
Most of the bridges associated with Perl Objective C / Cocoa died unfortunately. MacPerl has not been updated since 2005.
Almost all of the simplest methods require knowledge of at least a minimal amount of Applescript and calling the text of this script, although calling an interpolated osascript type.
In its 1-line form, osascript makes Perl beautiful:
osascript -e 'tell application "Finder"' -e "activate" -e "display dialog \"hello\"" -e 'end tell'
To use osascript from Perl, most use a HERE document. There are examples from a book I called Applescript - the ultimate guide and brian d foy on managing iTunes with Perl .
Here is the Perl script I wrote to adjust the color of the file using osascript:
#!/usr/bin/perl use strict; use warnings; use File::Spec; use String::ShellQuote; sub osahere { my $rtr; my $scr='osascript -ss -e '."'".join ('',@_)."'"; open my $fh, '-|', $scr or die "death on osascript $!"; $rtr=do { local $/; <$fh> }; close $fh or die "death on osascript $!"; return $rtr; } sub set_file_color {
If the Finder color is 0, kMDItemFSLabel is 0. If there is any color set, kMDItemFSLabel becomes 8-color. those. the orange label index is label index 1, kMDItemFSLabel = 7; the red label index is label index 2, kMDItemFSLabel = 6; etc.
dawg
source share