• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finder > Tags.. access
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finder > Tags.. access


  • Subject: Re: Finder > Tags.. access
  • From: Shane Stanley <email@hidden>
  • Date: Sun, 23 Dec 2018 14:02:01 +1100

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>
<www.macosxautomation.com/applescript/apps/>, <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

  • Follow-Ups:
    • Re: Finder > Tags.. access
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >Finder > Tags.. access (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Finder > Tags.. access
  • Next by Date: Re: Finder > Tags.. access
  • Previous by thread: Finder > Tags.. access
  • Next by thread: Re: Finder > Tags.. access
  • Index(es):
    • Date
    • Thread