Can't set file's label color

When I run this code…

set theFile to "Hard Drive:Users:wes:Documents:Automatic Duck:dev:install:file sets:AutoDuck Pro Import FCP:2.03:Installer Builds:Pro Import FCP 2.02C Site Install (Duck).app:"

tell application "Finder"
	set label index of theFile to 6
end tell

… I get this error…

What do I need to change to be able to get this to work? Thank you.

Model: Dual 2.0 G5
AppleScript: Version: 2.0 (43.1)
Browser: Safari 312.5
Operating System: Mac OS X (10.4)

Hi,

add the little word file and it works,
(you’re trying to change the label color of a literal string)

set theFile to "Hard Drive:Users:wes:Documents:Automatic Duck:dev:install:file sets:AutoDuck Pro Import FCP:2.03:Installer Builds:Pro Import FCP 2.02C Site Install (Duck).app:"

tell application "Finder"
	set label index of file theFile to 6
end tell

Wow! Thank you for the fast solution.

I picked up this >15 year snippet which still works!
Than deleted the post because I managed to get 2 color labels but can’t seem to reproduce?

Reposting again because I have 2 questions

  • if I run multiple set label index only the last one seems to be applied.

  • How can I combine 2 string variables after for theFile

Applescript:

set theFile to "Macintosh HD:Users:anton:test.pdf"
-- set myPath to "Macintosh HD:Users:anton:"
-- set myFile to "test.pdf"
tell application "Finder"
    set label index of file theFile to 4 -- blue
    set label index of file theFile to 5 -- purple
    -- set label index of file myPath & myFile to 6 -- gray
end tell

OK I found how to separate file from folders

set label index of document file myFile of folder myPath to 4 -- blue
or
set label index of file (myPath & myFile) to 6 -- gray

Now only to get multiple tags set…
which I can only get to work with another run of the script for another color

FWIW, using two separate set label lines works for me. Sometimes the finder window doesn’t update visually, at least not immediately. Dunno if that’s a factor here.

Hi, no it doesn’t work for me, I am on Big Sur 11.7.2

Playing around with the TAG command line tool now:
https://github.com/jdberry/tag
plug to @ wch1zpink mentioning this

installed with Homebrew:
brew install tag

or MacPorts
sudo port install tag

example:

on mySetTag(myTag, myDir, myFile)
	do shell script "/usr/local/bin/tag -a" & space & myTag & space & myDir & myFile
end mySetTag
mySetTag("Red,Yellow,Green,'Rasta Power'", "/Users/anton/Desktop/", "test.pdf")
1 Like