Dear Anybody,
I have looked through the finder dictionary and some others and found no reference. I have looked online and not found it either. I feel i might not be using the right search argument.
I need to write a string value to a file tag from an Applescript. Specifically, i am taking mail attachments and writing these to disc. As I do so, i want to add a tag which will consist of the mail senders email address.
Then, a separate script can later on construct a new mail once the attachment has been processed.
I am unable to find tags shown as file properties in the dictionary or in the apple guide.
Am I dim or is it not there?
Max
he only way you can do it is with AppleScriptObjC. here’s code for dealing with tags; for Mavericks, you need to save it as a script library.
use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
on returnTagsFor:posixPath -- get the tags
set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL
set {theResult, theTags} to aURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(missing value)
if theTags = missing value then return {} -- because when there are none, it returns missing value
return theTags as list
end returnTagsFor:
on setTags:tagList forPath:posixPath -- set the tags, replacing any existing
set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL
aURL's setResourceValue:tagList forKey:(current application's NSURLTagNamesKey) |error|:(missing value)
end setTags:forPath:
on addTags:tagList forPath:posixPath -- add to existing tags
set aURL to current application's |NSURL|'s fileURLWithPath:posixPath -- make URL
-- get existing tags
set {theResult, theTags} to aURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(missing value)
if theTags ≠missing value then -- add new tags
set tagList to (theTags as list) & tagList
set tagList to (current application's NSOrderedSet's orderedSetWithArray:tagList)'s allObjects() -- delete any duplicates
end if
aURL's setResourceValue:tagList forKey:(current application's NSURLTagNamesKey) |error|:(missing value)
end addTags:forPath:
Shane, thanks.
I’m just learning so I’ll sit and read this carefully. I still walk in fear of anything outside Applescript itself
Max