Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1098089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:31:39+00:00 2026-05-17T00:31:39+00:00

Does anyone know if it is possible to directly edit file metadata on OS

  • 0

Does anyone know if it is possible to directly edit file metadata on OS X. Specifically in perl. The parameter I’m specifically trying to change is kMDItemFSLabel (The color of the file). I’ve had a search around and I can’t seem to find a way to do this without using a module such as Mac::Glue or an external application (Finder).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:31:40+00:00Added an answer on May 17, 2026 at 12:31 am

    The kMDItemFSLabel attribute is a property of the Finder. You need to use a way to communicate with the Finder to change its data. As far as I know, there is no bit you can twiddle with Perl to change the Finder’s data without going through the Finder.

    There are several ways to do this:

    1. Use CamelBones when the new version comes out. That allows a bridge to Objective C from Perl. Then you will need to use the Apple method with Cocoa system calls. Steep learning curve for Cocoa…

    2. If you have developer tools, use /Developer/Tools/SetFile (if that supports the metadata item)

    3. Use osascript to send the message to the Finder to change the color of the file. You can look at this earlier SO post for hints on doing that.

    Most of the Perl related Objective C / Cocoa bridges have died unfortunately. MacPerl has not been updated since 2005.

    Almost all the easiest methods require knowing at least minimal amount of Applescript and calling the text of that script though an interpolated type call to osascript.

    In its 1 line form, osascript makes Perl look 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 I book I have called Applescript – The Definitive Guide and from brian d foy on Controlling iTunes with Perl.

    Here is a script in Perl I wrote for setting file color 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 {
    # -- No color = 0
    # -- Orange = 1
    # -- Red = 2
    # -- Yellow = 3
    # -- Blue = 4
    # -- Purple = 5
    # -- Green = 6
    # -- Gray = 7
    
    my $file=shift;
    my $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;
    
    my $rtr=osahere <<"END_SET_COLOR" ;
    tell application "Finder"
        set f to "$file"
        set ItemToLabel to POSIX file f as alias
        set the label index of ItemToLabel to $color
    end tell
    END_SET_COLOR
    
    return $rtr;
    }
    
    set_file_color("2591.txt",2);
    

    If the Finder color is 0, kMDItemFSLabel is 0. If there is any color set, kMDItemFSLabel becomes 8-color. ie, label “orange” is label index 1, kMDItemFSLabel = 7; label “red” is label index 2, kMDItemFSLabel = 6; and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.