Page 1 of 1

How do you write file tags to OSX files?

Posted: Thu Jan 12, 2017 9:47 pm
by Simon Knight
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

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

Posted: Fri Jan 13, 2017 12:02 pm
by Thierry
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

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

Posted: Mon Jan 16, 2017 7:59 am
by Simon Knight
Thanks Thierry,

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

Thanks