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.

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)

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!