• 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: Another impossible feature?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another impossible feature?


  • Subject: Re: Another impossible feature?
  • From: Yvan KOENIG <email@hidden>
  • Date: Thu, 09 Mar 2017 18:45:16 +0100

In your folder action scripts add these instructions:


use AppleScript version "2.4" # Yosemite or higher
use framework "Foundation"
use scripting additions


on adding folder items to this_folder after receiving these_items
-- Defines the path to the alias. 
-- If I understand well it's on the Desktop.
-- I assume that it has the same name that the original folder


tell application "Finder"
set itsName to name of this_folder
set nbItems to 1 + (count (get items of this_folder))
end tell


# Choose your preferred syntax
-- set leDossier to ((path to desktop as text) & itsName) as alias
# or
-- set leDossier to ((path to desktop as text) & itsName) as «class furl»
# or
set leDossier to POSIX path of ((path to desktop as text) & itsName)


set tagNames to (current application's NSWorkspace's sharedWorkspace()'s fileLabels()) as list
--> {"Aucun", "Gris", "Vert", "Violet", "Bleu", "Jaune", "Rouge", "Orange"}
if nbItems ≤ (count tagNames) then
my setTags:{tagNames's item nbItems} forItem:leDossier
end if


end adding folder items to

# Borrowed to Shane STANLEY
-- Replace tags; pass a list of the new tags plus a file, alias or POSIX path
on setTags:tagList forItem:fileOrPosixPath
if class of fileOrPosixPath is not text then set fileOrPosixPath to POSIX path of fileOrPosixPath
set thisURL to current application's class "NSURL"'s fileURLWithPath:fileOrPosixPath -- make URL
set {theResult, theError} to thisURL's setResourceValue:tagList forKey:(current application's NSURLTagNamesKey) |error|:(reference)
if theResult as boolean is false then error (theError's |localizedDescription|() as text)
end setTags:forItem:


Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) jeudi 9 mars 2017 18:39:18



 _______________________________________________
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

References: 
 >Another impossible feature? (From: Robert Poland <email@hidden>)

  • Prev by Date: Another impossible feature?
  • Next by Date: Re: collectdata
  • Previous by thread: Another impossible feature?
  • Next by thread: Re: Another impossible feature?
  • Index(es):
    • Date
    • Thread