How do you set the Mac File Tag from KM?

In KM I want to:

  1. Save File As: STRING%VARIABLE%.jpg (e.g. Fred-1.jpg, Fred-5.jpg, etc.)
  2. Set this jpg file’s tag = GREEN

Any ideas? Thanks.


Set up a Finder group, so that whatever you put into that folder will only be activated when you have the Finder at ihe front. That can be done by setting the folder’s available activation is Finder.


In the Macros column, create a new macro with the title of something like: Color 0 - None
Set the Hot Key for something obvious, or whatever you like, for example: Control-0
Click on the little Plus sign at the bottom of the new marco to get the list of functions
Click on Execute=> Execute Applescript and add the resulting template to the Macro
Set the template to Execute Text Script and Ignore Results

in the empty area, paste in this AppleScript:

tell application "Finder"
  set these_items to (selection)
end tell
repeat with i from 1 to the count of these_items
  set this_item to (item i of these_items)
  tell application "Finder"
    set the label index of this_item to 0 --label value, 0 is no label, 1 Orange, 2 Red, 3 Yellow, 4 Blue, 5 Purple, 6 Geen, 7 Gray
  end tell
end repeat

– Source is dtomasch

It’s essentially the same as the script found at the link below, except that I’ve put in the various colours and numbers to remind you what number to set,

Now, copy and paste to create new copies of that first macro, adjusting the name of the macro, the trigger key and the number at the end of this line to get the colour you want: set the label index of this_item to 0

There are a couple of other approaches which you may like better, noted on the following linked page:

Hope this helps.


Hey Steve,

Generally I prefer to do this sort of job with AppleScript, because it's easier for me to write and often a bit more flexible than Keyboard Maestro.

However – you can't set tags with vanilla AppleScript.

You can do so with AppleScript-ObjectiveC, but that gets rather complicated.

Labels and the colored Tags appear to be the same, but they are not. If you label something Green and search for Green Tags you WON'T find the Green-labeled items.

Doing this job with Keyboard Maestro isn't exactly intuitive, because of the need for variable-tokens and the fact that renaming an item is done by moving it.

But. Once you've worked with the Finder-selection a few times this stuff becomes MUCH easier, because you become used to the concepts and steps involved.

(Scope out the wiki Finders Selection page, and the forum topic Working with the Finder Selection)


Finder → Rename and Sequentially Number Selected Items.kmmacros (6.2 KB)


Chris, thanks for sharing that.

####Does the Mac OS, starting with Mavericks, still support "Labels"?
I thought all labels got converted to Tags. Am I wrong?

I did some searching and couldn't find any way to set a file Label post Mavericks (I'm on Yosemite now).

OK, I just did an interesting test with Finder.
It appears that "File Label" refers to the color of Tags, not the name of the Tag.
So, I did a search for File Label = Yellow, and here is what it found:
Files tagged with tags that have a yellow color, even though the Tag name is different.

So, I still don't see any way to set a File Label apart from setting a Tag. Is this correct?

BTW, the reason the entire line in Finder is highlighted by the tag color is that I use TotalFinder, which provides this feature.

1 Like

Hey JM,

# Auth: Christopher Stone
# dCre: 2010/09/23 16:54
# dMod: 2015/12/22 19:40
# Appl: Finder
# Task: Set File Label to 6 (Green).
# Libs: ELb
# Osax: None
# Tags: @Applescript, @Script, @Set, @Finder, @Label

tell application "Finder"
  set sel to selection as alias list
  if sel ≠ {} then
    if (name of front window) does not start with "Searching " then
      set insertionLocation to target of front window as alias
      set insertionLocation to missing value
    end if
  end if
  repeat with i in sel
    set label index of i to 6
  end repeat
  if insertionLocation ≠ missing value then update insertionLocation
end tell


This stuff gets very tricky.

On the left I've searched for tag:orange using the general search field in the Finder toolbar.

It finds both labels and tags that are orange or Orange.

On the other hand if I search using the Spotlight UI in the Finder window for Tag > Matches > Orange I find only the Tag 'Orange'.

If I use the Spotlight-UI to search for the Label 'Orange' as you did above it will pick up the items Tagged 'Orange'.

This crap comes into play when you search for labels or tags programmatically as well.

We went round-and-round testing this out on the Applescript Users List sometime in the last year or so using a 3rd party command-line utility that searches for and sets tags and ASObjC thanks to Shane Stanley.



Chris, thanks for the AppleScript, but I meant using just the UI.

I see no reason to use Labels at this point, and AFAIK, I don't have any true Labels. The Finder search I showed above shows I always have a tag for each Label color.

Therefore, I will use only Tags in:

  • Searches
  • Code

This should avoid any confusion, at least for me. :wink:

This opens up use of the Finder File Label field to search for all tags of a specific color.
This could be useful where I always use "Yellow" colored tags to denote the most important stuff, and use the Tag name to denote its category.

So, I can do the following Finder searches:

  1. by Tag name to find all files of a specific category
  2. by Label color to find all files of a particular importance, regardless of category

Having said that, it's probably better to use this approach:

  • Use separate tags for category and importance

But actually, I don't do a lot of tagging in Mac files.

I use Evernote and IQTell to manage all of my personal and business information, including catogorizing by tags and notebooks. In Evernote, I can link to whatever files I need, OR attach them to a Note, whichever is more appropriate.

I use Mac tags in a limited way, mostly to identify/highlight:

  • Very important files
  • Files in development
  • Special files, like aliases and symbolic links
  • Favorites (like in a folder of photos)

But that's just me. Everybody has a different preference/way of organizing their stuff.

Sorry @cvc8445 for getting so far off-topic. And now back to your regularly scheduled program. :wink:

1 Like

If you've used Labels on your system in the past you will likely have problems with the tag/label differentiation at some point – unless you go through and make sure any items that are "labelled" are really tagged.

You can still set labels via AppleScript, but unfortunately in the Finder's UI these are indistinguishable from Tags.

You can end up with a items that have both an Orange Tag and an Orange Label, but you won't be able to tell unless you look at the metadata for the file in the Terminal:

mdls <path>

This mixed-up-mess should be easy to fix, but it takes a bit of savvy and effort.


1 Like

Why wouldn't the approach I used work:

  • Do a finder search for File Label
  • Be sure to show the Tags column in the Finder
  • Go through each Label color, and look for files with no tag.
  • You can even sort on the Tag column, and all of the files without a tag will be grouped together.
1 Like