Here's what I got, but I ave a custom label with "Active Projects". How do I assign?
tell application "Finder" to set label index of theFile to 5
Here's what I got, but I ave a custom label with "Active Projects". How do I assign?
tell application "Finder" to set label index of theFile to 5
You can't do that with vanilla AppleScript. The Finder dictionary does not support adding tags.
However you can do it with AppleScriptObjC which gives access to the Foundation framework
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
on addTagToPath(theTag, thePath)
set theURL to current application's NSURL's fileURLWithPath:thePath
set {success, tagArray, theError} to theURL's getResourceValue:(reference) forKey:(current application's NSURLTagNamesKey) |error|:(reference)
if theError is not missing value then error theError's localizedDescription() as text
if tagArray is not missing value and (tagArray's containsObject:theTag) as boolean is true then return
if tagArray is missing value then set tagArray to current application's NSMutableArray's array()
tagArray's addObject:theTag
set {success, theError} to theURL's setResourceValue:tagArray forKey:(current application's NSURLTagNamesKey) |error|:(reference)
if theError is not missing value then error theError's localizedDescription() as text
end addTagToPath
and use it
try
addTagToPath("MyTag", "/Users/myUser/path/to/file.ext")
on error e
log e
end try
The try
block catches errors thrown by the NSURL
methods