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

Rép: Another impossible feature?


  • Subject: Rép: Another impossible feature?
  • From: Yvan KOENIG <email@hidden>
  • Date: Sat, 11 Mar 2017 14:06:51 +0100


As far as I know, we can't have two folder action scripts active upon a single folder.
If you attach a script triggered when you add items to a folder you can't use an other script to be triggered when you remove items.
Maybe - I never tried - you may have the two handlers in the same script.

Here is a script using an other scheme.
It must be saved as a stay open application.
Every ten seconds it will poll the defined items.
What is fine is that we just have to define the alias to treat. The script will grab the path to the original items by itself.
I must thank's Shane STANLEY which gave me the correct syntax required to to that with ASObjC.

##################################
# on idle.app
# This script MUST be saved as a stay open application
# In real life put it in the list of files to launch on boot.
# to try, just double click its icon
##################################


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

#=====

on run
--
end run

#=====

on idle
set |⌘| to current application
set p2d to path to desktop as text
set theAliases to {"my alias", "tempo"}  #<<<<<<<<<<<<<<<<<<<<<<< Edit to fit your needs
repeat with theAlias in theAliases
set aliasURL to (|⌘|'s class "NSURL"'s fileURLWithPath:(POSIX path of (p2d & theAlias)))
set {originalURL, theError} to (|⌘|'s class "NSURL"'s URLByResolvingAliasFileAtURL:aliasURL options:0 |error|:(reference)) # Thank's to Shane STANLEY
set fileManager to |⌘|'s NSFileManager's defaultManager()
set theFiles to (fileManager's contentsOfDirectoryAtURL:originalURL includingPropertiesForKeys:{} options:(|⌘|'s NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value))
set nbItems to 1 + (count theFiles)

--set tagNames to (current application's NSWorkspace's sharedWorkspace()'s fileLabels()) as list
--> {"Aucun", "Gris", "Vert", "Violet", "Bleu", "Jaune", "Rouge", "Orange"}

set thisLocale to |⌘|'s NSLocale's currentLocale()
if (thisLocale's countryCode as text) is not "FR" then
# Try with a non-standard list matching Robert's wishes
set tagNames to {"None", "Orange", "Red", "Yellow", "Blue", "Purple", "Green", "Gray"}
else
# Define the same list in French
set tagNames to {"Aucun", "Orange", "Rouge", "Jaune", "Bleu", "Violet", "Vert", "Gris"}
end if

if nbItems > (count tagNames) then set nbItems to (count tagNames)

set theTag to item nbItems of tagNames

(my setTags:{theTag} forItem:originalURL)
(my setTags:{theTag} forItem:aliasURL)

end repeat

return 10 # period of 10 seconds. You may use 5 seconds #<<<<<<<<<<<<<<<<<<<<<<< Edit to fit your needs
end idle

# Customisedd version of a handler borrowed to Shane STANLEY
-- Replace tags; pass a list of the new tags plus an URL
on setTags:tagList forItem:thisURL
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:

#=====

on quit
continue quit
end quit

#=====


Yvan KOENIG running Sierra 10.12.3 in French (VALLAURIS, France) samedi 11 mars 2017 14:02:41





 _______________________________________________
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: Another impossible feature?
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Re: URLByResolvingAliasFileAtURL
  • Next by Date: Re: Another impossible feature?
  • Previous by thread: Re: URLByResolvingAliasFileAtURL
  • Next by thread: Re: Another impossible feature?
  • Index(es):
    • Date
    • Thread