perl - How can I edit file metadata in OS X? -


does know if possible directly edit file metadata on os x. in perl. parameter i'm trying change kmditemfslabel (the color of file). i've had search around , can't seem find way without using module such mac::glue or external application (finder).

the kmditemfslabel attribute property of finder. need use way communicate finder change data. far know, there no bit can twiddle perl change finder's data without going through finder.

there several ways this:

  1. use camelbones when new version comes out. allows bridge objective c perl. need use apple method cocoa system calls. steep learning curve cocoa...

  2. if have developer tools, use /developer/tools/setfile (if supports metadata item)

  3. use osascript send message finder change color of file. can @ this earlier post hints on doing that.

most of perl related objective c / cocoa bridges have died unfortunately. macperl has not been updated since 2005.

almost easiest methods require knowing @ least minimal amount of applescript , calling text of script though interpolated type call osascript.

in 1 line form, osascript makes perl beautiful:

osascript -e 'tell application "finder"' -e "activate" -e "display dialog \"hello\"" -e 'end tell' 

to use osascript perl, use here document. there examples book have called applescript - definitive guide , brian d foy on controlling itunes perl.

here script in perl wrote setting file color using osascript:

#!/usr/bin/perl use strict; use warnings; use file::spec; use string::shellquote;   sub osahere  {      $rtr;     $scr='osascript -ss -e '."'".join ('',@_)."'";     open $fh, '-|', $scr or die "death on osascript $!";     $rtr=do { local $/; <$fh> };     close $fh or die "death on osascript $!";     return $rtr; }  sub set_file_color { # -- no color = 0 # -- orange = 1 # -- red = 2 # -- yellow = 3 # -- blue = 4 # -- purple = 5 # -- green = 6 # -- gray = 7  $file=shift; $color=shift || 0; $color=0 if $color<0; $color=7 if $color>7;  $file=file::spec->rel2abs($file)      unless file::spec->file_name_is_absolute( $file ); $file=shell_quote($file);  return undef unless -e $file;  $rtr=osahere <<"end_set_color" ; tell application "finder"     set f "$file"     set itemtolabel posix file f alias     set label index of itemtolabel $color end tell end_set_color  return $rtr; }  set_file_color("2591.txt",2); 

if finder color 0, kmditemfslabel 0. if there color set, kmditemfslabel becomes 8-color. ie, label "orange" label index 1, kmditemfslabel = 7; label "red" label index 2, kmditemfslabel = 6; , on.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -