Re: Setting a coloured label
Re: Setting a coloured label
- Subject: Re: Setting a coloured label
- From: Helmut Fuchs <email@hidden>
- Date: Wed, 14 Sep 2016 16:21:54 +0200
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
Yvan KOENIG schrieb:
Hello
I wish to set the label of a folder to red.
My first attempt was to use set label index to 2
but, if the folder has already a label, the old one is not replaced, a
new one is just added.
I tried to remove the existing label using set label index to 0 but it
didn't do the trick.
*set* wantedLabel*to* 2
*set* aFolder*to* *choose folder*
*tell* /application/"Finder"
*if* label index*of* aFolder*is* *not* wantedLabel*then*
*log*"point 1"
*if* label index*of* aFolder*is* *not* 0 *then*
*log*"point 2"
*set* label index*of* aFolder*to* 0
--open aFolder
*repeat* 20 *times*
*tell* *me* *to* *delay*0.1
*update*aFolder
*log*"point 3"
*if* label index*of* aFolder*is* 0 *then* *exit* *repeat*
*log*"point 4"
*end* *repeat*
--close window 1
*end* *if*
*log*"point 5"
*set* label index*of* aFolder*to* wantedLabel
*end* *if*
*end* *tell*
As the folder was originally labelled in blue, the result was two labels
: blue and red.
So, i decided to use ASObjC using a code written by Shane Stanley.
I just added a complementary handler returning the localized names of
the colors because it's what me must pass to the code.
The draft code became :
*use* AppleScriptversion"2.3.1"
*use* /scripting additions/
*use* /framework/"Foundation"
*on* setTags:tagListforItem: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'ssetResourceValue:tagListforKey:(/current
application's/NSURLTagNamesKey) |error|:(/reference/)
*if* theResult*as* /boolean/*is* /false/*then* *error*
(theError's|localizedDescription|() *as* /text/)
*end* setTags:forItem:
*on* getLabelsNames()
*return* (/current application's/NSWorkspace'ssharedWorkspace()'s
fileLabels()) *as* /list/
--> {"Aucun", "Gris", "Vert", "Violet", "Bleu", "Jaune", "Rouge", "Orange"}
*end* getLabelsNames
*set* target*to* POSIX path*of* (*choose folder*)
*my* setTags:{/item/-2 *of* *my* getLabelsNames()} forItem:target
Is there a way to set the colored label without having to extract the
list of localized names ?
Yvan KOENIG running El Capitan 10.11.6 in French (VALLAURIS, France)
mercredi 14 septembre 2016 16:09:37
_______________________________________________
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
_______________________________________________
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