[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Setting a file's label ; label #s



> >    Is there a way to access and set a file's label through MacPerl?  By
> >"label," I mean that which you can set through the Label submenu form
> >the Finder's File menu.
> 
> Check bits 1-3 of fdFlags() in FInfo.
> 
>   #!perl -w
>   use Mac::Files;
>   $file = $ARGV[0];
>   $FInfo = FSpGetFInfo($file);
>   $flags = $FInfo->fdFlags();
> 
> You can assign a value back to fdFlags and then to the file like:
> 
>   $FInfo->fdFlags($newvalue);
>   FSpSetFInfo($file, $FInfo);


That seems not to work for directories.  What to do for those?



Incidentally, I working up the following code...

sub read_label {
  my($item) = $_[0];
  my($flags);

  return undef unless -e $item;
  if(-f _) {
    $FInfo = FSpGetFInfo($item); # Should I have my()'d $FInfo?
    $flags = $FInfo->fdFlags();
  } elsif (-d _) {
    return undef; # What to do?
  } else { # ?!
    return undef;
  }
  return ($flags & 14) >> 1; # 14 = 00001110 b
}

...which works, but I've noted that the above returns 0 for no label, 7
for orange/"Essential" and down to 1 for Brown/"Project 2".  But I'm
fairly certain that under AppleScript (as in "set label index of folder
"Whatever" to 2) it's 0 for none, 1 for orange/"Essential" and up to 7
for Brown/"Project 2".  Am I doing something wrong that's producing this
difference, or is this just one of those things?

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch