On Mac OS: Insert A Directory Path for Finder 'Go To Folder' Selection

I'm working on creating a single Macro that will open six Mac finder windows, each showing a specific directory. These folders will show the progress of files on an automated pipeline for content production.

I'm able to create a Macro that draws all six windows in position just as I want them to be. My only problem is that I'm trying to insert a directory path for each window and i can't get these to work. I know how to copy a full path on a Mac (just like it is so easy to do on a Windows PC, example: /Users/acrosby/Zash Global Media Dropbox/Magnifi_U_Video_PipeLine/Finished_Course_Video_In)

But, I don't know how to insert this text after the finder selection 'Go to folder'. The insert text function didn't work for me. I even tried inserting a 'return' after it, but that still yielded no results.

The included screen grab above is not the macro that shows all six windows in position, it is of only a single attempt to have the Mac window 'go' to a specific directory location in KM. See area with red box, and/or the segment above it.

I'm new to the forum, and Keyboard Maestro ... but I feel I'm close ... just missing that one piece that makes it all work. Thanks for any help!

Instead of invoking the Finder Go Menu try using the Action called "Open a File, Folder or Application"
Set the path to the the folder as you have
and choose to open with "Finder"

1 Like

Consider using an AppleScript.

This one opens two windows (desktop and my user folder). You can do more folders by repeating the script.

You'll have to use your own paths and window sizes (bounds), as I have a large monitor.

I hope that helps!

tell application "Finder"
	activate
	open ("/users/Jim/Desktop/" as POSIX file)
	set the sidebar width of Finder window 1 to 165
	set the current view of Finder window 1 to column view
	set bounds of Finder window 1 to {0, 0, 1400, 530}
end tell

tell application "Finder"
	open ("/users/Jim/" as POSIX file)
	set the sidebar width of Finder window 1 to 165
	set the current view of Finder window 1 to column view
	set bounds of Finder window 1 to {0, 552, 1400, 1080}
end tell

Thanks for this, it was a great help in getting me where i needed to be on this automation.
Using the 'Open a file, folder, or application' function definitely makes, and it's a lot neater and easier than the technique I was using before. I appreciate the help, I've learned!

With the help of the previous reply from Zabobon, I was able to economize my setup and get a single window to work without issues. I then made six single KM macros and strung them together using Applescript (exported as an app) - that worked wonderfully.

I'm sure I could have put this together using only Applescript as you suggested, but I'm new to Keyboard Maestro and was wanting to gain some skills there.

You've shown me (a newbie) that combining Keyboard Maestro and Applescript is a great way to go ... I'll try the whole thing in Applescript someday soon when I'm a bit more sure-footed. Thanks again!

1 Like

(the above reply was meant for 'Jim')

1 Like

Here is a screen grab of a 'single' KM macro that was placed in to Applescript six times with different file paths and window locations:

And here is a portion of the Applescript where i strung 6 KM Macros together as an executible:

Just to let you know, you can do this many ways (i.e. repeat basically the same thing with different paths) within Keyboard Maestro itself without having to use AppleScript.

To just fire your existing six Macros one after the other, you could have a Macro that fires them, using six Execute Macro Actions one after the other (this is doing basically the same thing as your AppleScript).

Or you could just put all your Actions into one long Macro (i.e. copy and paste your existing Actions from the six Macros, one after the other in a single Macro).

There are other ways, such as using a Subroutine and Variables for the path name and coordinates, but either of the two suggestions above will mean not having to use any tools outside of Keyboard Maestro.

I'll definitely try what you've suggested regarding the six Execute Macros Actions. I guessed that while i was assembling the six KM macros in Applescript there had to be a way to do that.
I did try to stack all the macros together in to one KM Macro, but it go hung up when it executed. I tried telling to to go back to the finder, but that had no effect.

I'll get there - at present I'm sticking with what works while I build the remainder of this automation pipeline. Thanks for your help!

1 Like

Hey Jim,

No need for multiple Finder-Tells โ€“ and those particular folders are available as path-to parameters which enable you to avoid hard coding the paths.

tell application "Finder"
   activate
   
   open (path to desktop folder)
   tell front Finder window
      set its sidebar width to 165
      set its current view to column view
      set bounds to {0, 23, 844, 900} # {0, 0, 1400, 530}
   end tell
   
   open (path to home folder)
   tell front Finder window
      set its sidebar width to 165
      set its current view to column view
      set its bounds to {596, 23, 1440, 900} # {0, 552, 1400, 1080}
   end tell
   
end tell

You can also expand tilde or $HOME based POSIX Paths quite easily provided they actually exist on disk:

set tildePathStr to "~/"

tell application "System Events"
   set fullPosixPath to POSIX path of disk item tildePathStr
end tell

To normalize a tilde path without the item being on disk already you need to jump through a few hoops with vanilla AppleScript or employ a line of AppleScriptObjC:

--------------------------------------------------------
use AppleScript version "2.4" --ยป Yosemite or later
use framework "Foundation"
use scripting additions
--------------------------------------------------------

set tildePathStr to "~/Pie in the Sky"
set fullPathString to ((current application's NSString's stringWithString:tildePathStr)'s stringByExpandingTildeInPath) as text

--------------------------------------------------------

-Chris