• 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: Setting a coloured label
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting a coloured label


  • Subject: Re: Setting a coloured label
  • From: Yvan KOENIG <email@hidden>
  • Date: Wed, 14 Sep 2016 21:37:13 +0200


Le 14 sept. 2016 à 16:21, Helmut Fuchs <email@hidden> a écrit :

Hi Yvan,

I've been using something like that:

try
do shell script "xattr -d com.apple.metadata:_kMDItemUserTags " & quoted form of the POSIX path of aFile
on error errString number errNumber
if errString does not contain "No such xattr" then
error errString number errNumber
end if
end try
tell application "Finder"
set label index of aFile to lColorIndex
end tell

My code is using the shell to clear the tags and then the Finder to add a label/tag.

Your approach with ASObjC is much more elegant - but if you don't find means to use an index, you might perhaps just clear the list of tags by giving setTagsForItem an empty list and use Finder scripting with an index afterwards...

Best,

Helmut


THANKS !

Of course, it was in front of me and I didn't saw the trick.

Here is the final code :

use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"

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:

set aFolder to (choose folder)

# Clear the existing tags
my setTags:{} forItem:(POSIX path of aFolder)
# Set the label to red
tell application "Finder"
set label index of aFolder to 2
end tell



Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France) mercredi 14 septembre 2016 21:37:08



 _______________________________________________
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: Setting a coloured label
      • From: Shane Stanley <email@hidden>
References: 
 >Setting a coloured label (From: Yvan KOENIG <email@hidden>)
 >Re: Setting a coloured label (From: Helmut Fuchs <email@hidden>)

  • Prev by Date: Re: Setting a coloured label
  • Next by Date: Re: Setting a coloured label
  • Previous by thread: Re: Setting a coloured label
  • Next by thread: Re: Setting a coloured label
  • Index(es):
    • Date
    • Thread