Repeat Macro if more than one file Selected

Hello, can anyone suggest a way to repeat this PathFinder macro if more than one file is selected. I have done some snooping on the forums and am unclear on how to implement this.

EDIT: I may not have been as clear as I should have been. What I mean is that the Text input is applied to all selected files instead of having to re-enter the same Text for every file that is currently selected.

If Then Else

Any suggestions would be greatly appreciated....Thanks

Here is the Macro I would like to build upon. 001__PathFinder » Rename File Beginning.kmmacros (28.8 KB)

If your objective is to rename every file in a selection, it will be much easier if you can use the macOS Finder. For example:

Here's the complete macro:
###MACRO: Rename Finder Selected Files With Sequential Number

If you must use PathFinder, then you will have to adapt.
There have been numerous topics/macros posted about using PathFinder.
See Posts with "PathFinder"

As I see it, you have two choices with PathFinder:

  1. Get a list of POSIX path of the files in the PathFinder selection, then process using the KM For Each action (KM Wiki).
  • Write an AppleScript to process the files in the selection.

#1 should be much easier.

Here is a JXA script to return a list of POSIX paths from Finder or PathFinder.
I have tested with "Fnder", but NOT with "PathFinder", since I don't have that app.
Can you please test this script in the Script Editor for a PathFinder Selection?

(function run() {    // will auto-run when script is executed.
    var ptyAppName = "Path Finder";  // "Finder" or "Path Finder"
    var fileList = Application(ptyAppName).selection();
    return fileList ?"\n") : "";

//~~~~~~~~   END OF MAIN SCRIPT ~~~~~~~~~~~

function getPOSIXPath(x) {
    var filePath = "";
    if (ptyAppName === "Finder") {
      filePath = decodeURI(x.url()).slice(7);
    else {  // "Path Finder"  
      filePath = x.posixPath();

    return filePath;
}  // --- END function getPOSIXPath ---

}  // --- END function run ---
)();  // --- END OF SCRIPT ---

Thanks JMichaelTX,
After reviewing your info it occurred to me to rearrange my macro so that it now works as I would like. All that was needed was to move the Prompt for User Input to before the For Each Item and it now works great!
Here is the new version if anyone else can use or learn from it.

Thank You!
001__PathFinder » Rename File Beginning.kmmacros (29.1 KB)

Glad you resolved your problem.

When you have time could you please test my above JXA script?



I have tried your script and am not sure exactly how to do this. Here are a few screenshots and a simple macro I used to try this test. My skills with Keyboard Maestro are very limited, I usually try to find examples for the few that I use and involve scripting.
JXA Test.kmmacros (25.9 KB)

This image is the output of a previous run of my working 001__PathFinder » Rename File Beginning.kmmacros. This is also the same output after trying to test your JXA script.

Output from the log after running JXA script.

Output from the Script Editor.

I will be happy to try again if you have some pointers....Thx

Many thanks for taking the time to test this.

The basic problem is that you are using "AppleScript" in both the Script Editor and the KM Action, whereas you should be using JavaScript for Automation:

###Script Editor

###KM Action

Here's your macro revised to use a Execute JavaScript for Automation Action, and display results in window.  We don't need either the Log or Display Window actions.  Please re-test and let me know the results.

###MACRO:   JXA Test

~~~ VER: 1.1    2017-06-03 ~~~

<a class="attachment" href="/uploads/default/original/2X/b/b690ad021d936a9c1d4d4232f31bb39a7ad3cb41.kmmacros">JXA Test.kmmacros</a> (24 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**


<img src="/uploads/default/original/2X/8/8538b28276b675b5e18ba24d6f13a746bfe53922.png" width="537" height="708">

Ok, I figured it was something very simple! This now appears to return the proper results.

Pathfinder results

I should be the one thanking you for the help/education. I only wish I had more free time to play with KM. If there is anything else I can do let me know.

Thanks again!!

1 Like

OK, that’s great! Thanks for testing this.

Well, that’s pretty much how it works around here – we are all helping each other. :smile:

1 Like