Tag Selected Files

This is a macro example to tag the selected files in the Finder with a pre-chosen tag (Red in this example). Adjust as needed.

3 Likes

Is it possible to use this macro in Path Finder, instead of Finder? Iā€™ve tried, and it does not work, nor can I find a way to adjust the input to be Path Finderā€™s selection.

One way to do it, though a bit of a hack, is to use the PathFinder menu item File/Reveal in Finder and then just call the Finder-specific macro

Keyboard Maestro does not have direct support for PathFinder. If PathFinder has AppleScript support, then it would be possible (both t do it yourself, and for Keyboard Maestro to potentially add support for it). Otherwise you're likely largely out of luck.

Path Finder's AppleScript support is rather crude, but you can get the selection amongst other things.

tell application "Path Finder"
	set fileList to selection
	repeat with i in fileList
		set contents of i to POSIX path of (get contents of i)
	end repeat
end tell
fileList

In the script you can change POSIX path to path to produce HFS paths.

Or you can change POSIX path of (get contents of i) to (get contents of i) as alias to produce a list of aliases.

-ccs

I just use the PathFinder menu:

1 Like

Labels and Tags are not the same thing, although the Finderā€™s UI will fool you into thinking so.

-Chris

Found this thread as I was trying to do the same thing- apply a tag to the selection(s) and relocate the file.

What I ended up doing is just use Finder with Keyboard Maestro for the tagging, since it does not work with Path Finder.

As part of the workflow I also have Hazel monitoring a directory, if I dump a bunch of files/folders into it and then using KM, tag them- Hazel will move them based on the tag.

Until I brought KM into the mix, Iā€™ve used just Hazel and Path Finder, tagging files myself as I keep Info, Tags, Hex Editor and Preview on the bottom shelf.

Hazel is using AppleScript too- and Iā€™ve had it manipulating files too- it works with Path Finder as the active application. Perhaps Hazel is actually doing a lot of that itself, but it gives the impression that Path Finder is doing the manipulation.

If it is actually Path Finder, perhaps Hazel holds some secrets that could be applied to Keyboard Maestro, as I donā€™t need Finder open if using that combination. Perhaps food for thought? ā€¦

Hey Tony,

There is NO need to use the Finder.

See this post (and thread).

-Chris

Iā€™m not having any success with it, Finder launches in the background. Nothing else happens.

Using the shorter Finder version from Finder works. Changing to the Path Finder derivative does not.

It also puts it in the comments area, though perhaps that is related to what I have read about AppleScript not supporting tags, but that was from 2014.

Iā€™ve come close to what I want on a few different fronts, but thereā€™s always something that wonā€™t make the process work.

In the end, if I can get the selected item(s) to get handed to this simple shell scriptā€¦

#!/bin/sh
~/tag --add %ExecutingMacro% %filePath%

Iā€™m placing the name of the script in the tag field. The command works directly otherwise.
Then it hit me. Spaces in the path. They need to be escaped ( '\ ')

Ugh.

You cannot use text tokens in an Execute Shell Script action.

You can use Keyboard Maestro variables as described in the Scripting section of the documentation.

So you need to first use the Set Variable to Text action to set a Keyboard Maestro variable to the text %ExecutingMacro%:

  • Set Variable Tag to Text %ExecutingMacro%

Then you need to execute the script:

#!/bin/sh
~/tag --add "$KMVAR_Tag" "$KMVAR_filePath"

Note that it is wise to wrap your variables in double quotes in case they have spaces in the path. However this also means that ~ will not be expanded, so if your path might start with ~, use the Filter Variable ā€˜filePathā€™ with Expand Tilde In Path action.

Hey Tony,

Please don't reference 3rd party executables without saying where they're from.

For that matter there is no need whatsoever to use a 3rd party tool for this job.

-Chris


Tag Selected Items in Path Finder.kmmacros (6.4 KB)

1 Like

Thanks! - now I learned something from that, too. Itā€™s also much faster than what I almost had working, practically instant, where as the other had a couple seconds lag at random.

Does this lack of any real AppleScript support in Path Finder mean that I should start with this as a base for file handling in Path Finder overall?

As for the third party script, that has been on all my installations for so long, and used fairly often, it slipped that it was an addition.


A command line tool to manipulate tags on Mac OS X files, and to query for files with those tags.

As for the variables and the shell commands, now I know. I had figured that since the script was actually in the macro, that it would work.

Hey Tony,

It looks like some basic operations such as move and duplicate actually function these days, but you'll have to experiment to see what else does and does not work.

Move and duplicate require a text path or a list of text paths (either posix or HFS).

When working with the Finder or other Mac-apps aliases are the least troublesome object reference.

------------------------------------------------------------
# Path Finder selection to list of aliases.
------------------------------------------------------------
tell application "Path Finder"
  
  set selectedPathFinderItems to selection
  
  repeat with i in selectedPathFinderItems
    set contents of i to (path of i) as alias
  end repeat
  
end tell

selectedPathFinderItems

When working with Keyboard Maestro or Unix executables then posix paths are the way to go.

-Chris

Chris,

Thanks for the notes. Pretty much then, just try it and if it works ā€¦ profit.
Otherwise use the alternate method.

I use posix whenever there is a choice. You know itā€™s just going to work.

What started as "I would love an application with a Midnight Commander-centric UI that is like a multi-tool for filing. I do a lot of sorting and packaging. The absolute reason I chose Path Finder way back was when Apple removed the able to use Drag Rectangle in a Finder List window. Then thereā€™s the window sill options that Path Finder has. A hex editor, ftype, preview and such are always at hand.

It was gladdening to find that the question had been asked before, on tagging by key press. With most of the answers I found in places. Use KM to have it open the dialog, add it and close the window.

Ummm. No.

But everything that ā€˜workedā€™ didnā€™t and I suspected Path Finder vs. Finder is playing into the equation. I have a set of Hazel rules that parse a single file tree and based on a combination of file names, content, types, it finds and moves. So I can move content to that directory and come back to it later, whatever is left, I do manually. I had KM just move them on a key selection but when something large needs to move between volumes, if the target drive is asleep, or an aliased share that isnā€™t mounted, or on a pinched connection, it causes momentary pausing.

From the Mac 128 onward you could lock the whole computer up by just pressing the mouse button. That went away when multithreading was actually what is says, however in OS X the similar behavior has resurrected itself in the form of the momentary wait when volumes are polled and drives have spun down.

If itā€™s primarily text files being parsed, I use grep with tag. <Bing!> Then it hit me, KM did get tag support ā€œHmmmā€¦ KM did get tag support a bit back, I can tag now and use similar Hazel rules to move it all later. Perfect!ā€ Then the thought of (why didnā€™t you think of that sooner???).

A bit of rambling here, but somewhat topic related. Hopefully the thread will further help others too.

Keyboard Maestro and Hazel. A dynamic duo!

The Set File Attribute action can both add a pre-existing color tag with a custom name); or create a new custom tag with a custom name, only without any color tag.

But is there a way to create a new color tag with a custom name in KM?
Something that would give the same result as setting a new custom color tag in Finder:

Screenshot 2024-12-13 at 13.55.35

Screenshot 2024-12-13 at 13.55.55

Setting the to field, in the Set File Attribute action, to Green,customText results in adding two tags: One "Green" (with green color tag, as this tag of course existed from before); and one "customText" (without any color tag). Cool that we're able to add several tags in one go though!

Illustrative Images

Keyboard Maestro Export

Screenshot 2024-12-13 at 13.04.09

And setting this same to field to either Green customText, Green"customText",<Green>customText, and the like, unsurprisingly results in adding a single tag of "Green customText", "Green"customText"","customText", etc. (without any color tag).

Illustrative Images

Keyboard Maestro Export

Screenshot 2024-12-13 at 13.45.03

So, does anyone know if it is possible to create a new color tag, with a custom name, (using KM) without first needing to create the custom tag manually in Finder?

AFAIK there's no way to create a new colour tag except via the Finder. Even the Apple Dev boards come up blank on this while the Finder's AppleScript dictionary has been showing

label n : (NOT AVAILABLE YET) A Finder label (name and color)

...for years.

From the little I understand the colour tags list isn't a thing in itself but an on-the-fly list of tags that are already applied to items, gathered via Spotlight.

1 Like

Hello Alex (@Alexander ):wave:

There are some solutions out there here is a Python library which allows you to create custom Tags with and without color.

But existing tags of this kind with a different color than defined will not be replaced - but used instead.

It requires python 3.7

There are of course other utilities out there but since Iā€™m currently reorganizing my References I am not able to find these other tools.

I hope this is helpful anyway.

Greetings from Germany :de:

Tobias

1 Like

I (happily!) stand corrected -- thanks, @Nr.5-need_input!

1 Like

Hello Nige (@Nige_S):wave:

There are of course some CLI Tools available which donā€™t require an installation of python.

I am sorry that I currently donā€™t have their Web Locations available.

Iā€™ll post them here as soon as I find the references again.

Greetings from Germany :de:

Tobias

2 Likes