Read TagInfo From File Macro (v10.2)

Read TagInfo From File Macro (v10.2)

Read TagInfo From File.kmmacros (5.8 KB)

Seemingly should be relatively simple to do this but maybe not understanding the KM iteration.

I have a plain text file with key value pairs delimited with a | character.
What I'd like to do is read each line, extract the value of each key and assign it to a variable to use based on the key name.

With my macro I can successfully read the file content that has been assigned to the TagValues variable but when attempting to iterate each line I don't get the content of each line using %Variable%SingleLine%

Instead I get the last line in the file when testing the output using the Display Text action.

Although I can clearly see all the lines are present when using %Variable%TagValues%
and even then the text is displayed only once as opposed to I'd expected being 4x in this case. 1 Display dialog per line. (4 lines of text)

Content of text file is:

ArtistName | Nomad
CDTitle | Day Of The Titan
ReleaseYear | 2024
Genre | Indie

I would think the collection has to be acknowledging the variable as a collection else it wouldn't have displayed the last line in the iterative value.

PLEASE NOTE: The %Variable%TagValues% is in the Display Text action only b/c I was testing the output

Ok, so after posting the question I tried several more times trying to determine why only the last line of the collection was being displayed using %Variable%SingleLine% and for whatever reason it finally worked.

Now I'm more baffled b/c of the inconsistent behavior.

Am I doing something wrong or is this some type of known periodic quirk? This isn't the first time I've noted something like this happening as if changes in the UI may be getting cached at times.

So, to get to what you want to achieve, you want the first line in your text file to be used to create a Variable called "ArtistName" with the value "Nomad" and so on for each line?

Is there a reason why you have those extra spaces? Could it be ArtistName|Nomad instead of ArtistName | Nomad?

Or even better, could your text file just be:

Day Of The Titan

Whatever, there will be a solution.

Hi @Zabobon thanks for the response.
There's no specific reason nor requirement that there's a space to either side of the pipe delimiter except perhaps for better readability when opening the file or when writing the content.

So those particular spaces could be removed as you've stated and presented as such:

ArtistName|Nomad and etc.

The Key (left side of the |) needs to be there though to allow flexibility for the values to be presented in any order and still be parsed with consistent result


Okay, so based on your original list

ArtistName | Nomad
CDTitle | Day Of The Titan
ReleaseYear | 2024
Genre | Indie

The below Macro will set a variable called the first half of each line, with the value from the second half of each line.

EXAMPLE Set Variables from List.kmmacros (4.4 KB)

Click to Show Image of Macro

To try and explain how it works...

" | " is used as a custom delimiter on each line. So each line can be divided into parts 1 and 2. Part 1 is used for the Variable name and part 2 is used for the content of that Variable.

If your delimiter was "|" without the spaces, %Variable%LOCAL__Line[1] | % would be written as %Variable%LOCAL__Line[1]|%

If you look at the Wiki Page, a little way down it talks about Variable arrays and customs delimiters in Keyboard Maestro.


Thanks @Zabobon !
I'll download this and give it a run.

I understand what you've done b/c it's fairly straight forward, nothing complicated for me.

I did btw modify my existing macro so it's identical to yours but for some reason when I press "try" nothing happens.

I still can't figure out why the "try" button works sometimes and other times w/o anything changing; it does absolutely nothing. :face_with_diagonal_mouth:

Really bizarre behavior.

Thanks for this. It works perfectly when I replaced the setting of the variables statically to read from the file.

Also I figured out that I have to navigate off of the macro and back before the Try button will work. Is this a known issue??? I checked for an update and it says I am running the most current. Yet I don't recall noting the UI working this way when I first purchased it.

I certainly would like to know if this is something others have reported or if my installation is somehow become corrupted.