Re: Finder > Tags.. access
Re: Finder > Tags.. access
- Subject: Re: Finder > Tags.. access
- From: Jean-Christophe Helary <email@hidden>
- Date: Sun, 23 Dec 2018 12:15:00 +0900
Thank you Shane.
For some reason the script does not give me the full list.
It gives me the list of tags applied to the selected item and then a list of
colors that I'm pretty sure I don't use anymore.
Also, the dialog does not allow me to remove a tag.
By the way, does assigning a shortcut to Tags... in System Preferences work on
your side ? If it does then I probably have to debug something here.
Jean-Christophe
> On Dec 23, 2018, at 12:02, Shane Stanley <email@hidden> wrote:
>
> What about taking a different approach. For example, if you're applying
> existing tags, you could use something like this:
>
> use AppleScript version "2.4" -- Yosemite (10.10) or later
> use framework "Foundation"
> use framework "AppKit"
> use scripting additions
>
> -- get existing tags plus default tags
> tell application "Finder" to set theFile to (item 1 of (get selection)) as
> alias
> set oldTags to my returnTagsFor:(POSIX path of theFile)
> set availableTags to current application's NSWorkspace's sharedWorkspace()'s
> fileLabels()
> set tagNames to current application's NSMutableSet's
> setWithArray:availableTags
> tagNames's addObjectsFromArray:oldTags
> set tagNames to (tagNames's allObjects()'s
> sortedArrayUsingSelector:"localizedStandardCompare:") as list
> -- show list
> set newTags to (choose from list tagNames with prompt "Choose tags to apply"
> default items oldTags as list with multiple selections allowed and empty
> selection allowed)
> if newTags is false then error number -128
> if newTags = {} then set newTags to missing value
> my setTags:newTags forPath:(POSIX path of theFile)
>
> 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:
>
>
> --
> Shane Stanley <email@hidden <mailto:email@hidden>>
> <www.macosxautomation.com/applescript/apps/
> <http://www.macosxautomation.com/applescript/apps/>>, <latenightsw.com
> <http://latenightsw.com/>>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden