So my end goal is to have KM automatically file a document based on files tags. Full disclosure I used a similar tool built in Ruby by Brett Terpstra (thanks Brett!) and am looking to build my own tool here.
I am looping through a folder looking for folders tags with a specific form. For each file I am using "get file attribute" action to get the tags for a file. The tag input manually into Finder is =PrimaryTag, :SecondaryTag1:Secondary Tag2. So in my test case I have two tags for my test file. Tag 1 is =PrimaryTag and Tag2 is :SecondaryTag1:SecondaryTag2.
So when I get the tags I have them placed in a variable, localTags. After I get the tags I then display them (a debug step at this point) and localTags[0] is 2, localTags[1] is ":SecondaryTag1:SecondaryTag2" and localTags[2] is "=PrimaryTag". This order of list elements seems backward to me based upon previous testing.
I intend to use the "=" sign and ":" signs to ID the path for filing the documents, so the order of the tags could be important when I parse the tags.
So my question for the forum is about the order of the tags. Should the tag order always be left to right as I read them in Finder, always be right to left, or follow some other more arbitrary rules??
MACRO: Get Finder Tag List (comma-delimited) of Finder Selection [Example]
**Requires: KM 8.2.4+ macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))
#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/9/a/9a4ae0d810f7b4c2d6019ce0f6eae858b59b84e8.kmmacros">Get Finder Tag List (comma-delimited) of Finder Selection [Example].kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**
---
### ReleaseNotes
Macro Author: @JMichaelTX
This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.
**MACRO SETUP**
* **Carefully review the Release Notes and the Macro Actions**
* Make sure you understand what the Macro will do.
* You are responsible for running the Macro, not me.
**==USE AT YOUR OWN RISK==**
* While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
* **Ask first**
* Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Topic Title: Order of tags
URL: https://forum.keyboardmaestro.com/t/order-of-tags/16847
Post Date: 2020-02-01
Posted By: AgingKeeper
For each file I am using "get file attribute" action to get the tags for a file. The tag input manually into Finder is =PrimaryTag, :SecondaryTag1:Secondary Tag2. So in my test case I have two tags for my test file. Tag 1 is =PrimaryTag and Tag2 is :SecondaryTag1:SecondaryTag2.
So when I get the tags I have them placed in a variable, localTags. After I get the tags I then display them (a debug step at this point) and localTags[0] is 2, localTags[1] is ":SecondaryTag1:SecondaryTag2" and localTags[2] is "=PrimaryTag". This order of list elements seems backward to me based upon previous testing.
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
<img src="/uploads/default/original/3X/8/6/86960af466174304ee1e3f46486c67e347a566f7.png" width="577" height="885">
Thanks for replying. Your script works as advertised. I suppose I can venture into AppleScript though I had hoped to avoid it since I spend more time fiddling with the syntax than I prefer.
I am just wondering if the expected behavior when I get tags is to have them in reverse order. It appears as if it reads the first tag puts it into the list and then "pushes" subsequent tags onto the list at the starting element.
I have included several screen shots of the windows I created to debug as well as a screen shot from Finder showing the file and tags. Lastly I included the KM macro itself.
I don't understand. You just repeated your above statement.
It's pretty clear to me that the Finder maintains an order.
So it must be the way you are retrieving the Tags in KM.
No matter, the ASObjC script works perfectly, and is very fast.