How do you write file tags to OSX files?

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
Simon Knight
Posts: 399
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

How do you write file tags to OSX files?

Post by Simon Knight » Thu Jan 12, 2017 9:47 pm

Hi,

I would like to add the ability to write key word tags to files in Mac OS X. I have found details in the LC dictionary of how to access the resource fork (OS9?) but not how to write to the extended attributes of Mac OSX files.

Googling suggests I need to use the OS command "xattr" and process some hex all via a shell command. However, I thought I'd ask if there is another way before I leap into the unknown.

So any thoughts?

Simon
best wishes
Skids

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 583
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: How do you write file tags to OSX files?

Post by Thierry » Fri Jan 13, 2017 12:02 pm

Simon Knight wrote: I would like to add the ability to write key word tags to files in Mac OS X.
However, I thought I'd ask if there is another way before I leap into the unknown.
Hi Simon,

not a direct answer but might give you some insights....

Code: Select all

on mouseUp
   // 2 parameters: a filename and a color
   constant myFile = "~/Desktop/testMe.txt"
   put "orange" into aColor
   
   // build a color array
   local Tcolor
   get TableColor(   "clear",  01, "gray", 03,  "green",  04,  "purple", 06, "blue",  09, "yellow", "0A",  "red" , "0C" ,"orange", "0E"  )
   put IT into Tcolor
   // from a valid color name get its value
   put Tcolor[ aColor] into aColor
   // set the xattr command
   get "xattr -wx com.apple.FinderInfo 000000000000000000%2s00000000000000000000000000000000000000000000 %s"
   // execute it
   if shell(  format( IT,  aColor, myFile)) is not empty then
      beep
      put "ERROR SHELL ! " &  syserror()
   end if
end mouseUp
  
 private function TableColor
    local newTable
    repeat with i= 1 to (the paramcount -1) step 2
       put  param( i+1)  into newTable[ param( i) ]
    end repeat
    return newTable
 end TableColor

This snippet of code will change the color Tags of a file
using the xattr terminal command.

Regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

Simon Knight
Posts: 399
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: How do you write file tags to OSX files?

Post by Simon Knight » Mon Jan 16, 2017 7:59 am

Thanks Thierry,

This is just the help I needed, I'll post again when I have completed some experiments.

Thanks
best wishes
Skids

Post Reply

Return to “Mac OS”