• 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: Sat, 11 Mar 2017 14:43:23 +0100

What an ass.

Just after sending my late message I saw that the list wished by Robert is the reverse of the standard one.
So there is no need to build a customized list based upon the language in use.

##################################
# 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 count theFiles


# Grab the standard list of tags
set tagNames to (|⌘|'s NSWorkspace's sharedWorkspace()'s fileLabels()) as list
--> {"Aucun", "Gris", "Vert", "Violet", "Bleu", "Jaune", "Rouge", "Orange"}


# A bit of trickery to apply Robert's wishes
set nbNames to count tagNames
if nbItems + 1 ≥ nbNames then
set idx to 2
else if nbItems = 0 then
set idx to 1
else
set idx to nbNames + 1 - nbItems
end if
set theTag to tagNames's item idx


(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

# Customised 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:42:44




 _______________________________________________
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: 
 >Rép: Another impossible feature? (From: Yvan KOENIG <email@hidden>)

  • Prev by Date: Rép: Another impossible feature?
  • Next by Date: Posix Path
  • Previous by thread: Rép: Another impossible feature?
  • Next by thread: Re: Another impossible feature?
  • Index(es):
    • Date
    • Thread