Process Last Line of Text and Add as Tags

Hi there,

I’ve been poring over the extremely helpful guidance here, but haven’t quite found what I am looking for. I have a collection of text files that each contain a series of hashtags. These hashtags are always on the last line of the file. What I’d like to be able to do is to select some of these text files in Finder, and then to execute a macro that would read the last line of each file, and would add the hashtag to the file as a macOS tag – removing the hash first, of course!

I’ve seen guidance in how to “Process Lines in Text File”, and other things that give me some sense of how it might be done, but does anyone have any ideas how this might be achieved? Hugely grateful in advance for any help!

Best,

Mark

Hi Mark,

Assuming the hashtags are always written #like #this and there are no other instances of hashtags in the files, this should get you started. Feel free to ask if you have any questions.

Read and Set Tags for Files.kmmacros (3.2 KB)
55 PM

Hi Gabe,

Very grateful for this – that works well! Perhaps it won’t be necessary to read only the last line of the file after all. The only issue I can see with this is that when using the macro with a number of selected files, the tags from the files above are also added to those below. Is there any way to prevent this from happening? Sorry once again, but I don’t know how to go about fixing that sort of issue.

Thanks in advance,

Mark

Glad to hear it works well for you! Sorry for the oversight with the combined tags. This new version below adds an action to wipe the LocalTags variable used to set the tags after they've been applied to each file, so it should now work as you expect.

Read and Set Tags for Files 1.1.kmmacros (3.5 KB)
27 PM

1 Like

Gabe, once again, thanks so much! I’m hugely grateful for this – solves a longstanding issue for a project of mine.

Best,

Mark

1 Like