Reveal or Open Folder Without Opening a New Window

I'm new to KM, trying to convert QuicKeys macros to KM. I've got a macro that adds a number of folders to the Finder sidebar. The folders are all on our server and sometimes get removed.

For each one, I want to go to a folder and than add it to the sidebar (using Control-Command-T). My problem is that the "Reveal a file" and "Open a file" actions each open new Finder windows so I end up with a dozen new windows on the screen. I suppose I could close each window, but isn't there an action or a trick to simply go to a location in the current window?

Thanks.

Hey John,

Welcome to the forum!  :smile:

Another QuicKeys refugee – welcome to the club. I finally gave up on it back around 2012, although I had the advantage of running Keyboard Maestro along side it since 2004 or so.

You're in for a bit of a culture shock. While Keyboard Maestro will do most everything QuicKeys would do – QuicKeys often made it easier on the user to perform routine tasks like renaming things in the Finder for instance.

Keyboard Maestro gives you the tools you need to create such workflows, but you have to learn how to use them first.

Transition from QuicKeys


Here's how to do what you want with AppleScript.

AppleScripts run in Keyboard Maestro's Execute an AppleScript actions.

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2020/12/22 12:42
# dMod: 2020/12/22 12:42 
# Appl: Finder, System Events
# Task: Change the Target of the Front Finder Window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @System_Events, @Change, @Target
--------------------------------------------------------
--» USER SETTING - Path to the destination folder
--» 	May be an alias or a HFS Path, or a POSIX Path string or a $HOME-based POSIX Path.
--------------------------------------------------------

set targetFolder to "~/Downloads/"

# Example
# set targetFolder to path to downloads folder

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

# Convert path into viable POSIX Path if necessary.
tell application "System Events"
   if class of targetFolder ≠ text then
      set targetFolder to targetFolder as text
   end if
   set targetFolder to POSIX path of disk item targetFolder
   if character -1 of targetFolder ≠ "/" then
      set targetFolder to targetFolder & "/"
   end if
end tell

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

# Change targetFolder back to a alias to be nice to the Finder.
set targetFolder to alias POSIX file targetFolder

# Change the Target of the Front Finder Window.
tell application "Finder"
   if exists of front window then
      set target of front window to targetFolder
   else
      error "No Windows are Open in the Finder!"
   end if
end tell

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

Here's how to integrate that with Keyboard Maestro:

Change Target Folder of the Front Finder Window v1.00.kmmacros (8.2 KB)

Keep in mind that you can also use the Go-To sheet in the Finder.

G

Brings up a sheet where you can change the path of the current window.

image

You can drive this critter with regular Keyboard Maestro actions:

This method works well and is pretty fast, but it's clunkier than the AppleScript.

NOTE:

If I was going to create a bunch of sidebar items to known locations I'd probably create an empty folder – then create aliases to the known paths en mass with AppleScript – and then drag them to the Finder sidebar.

I'd have to make sure this method worked with a network share though.

I hope this give you a boost on your Keyboard Maestro journey.

-Chris

Wow, thanks Chris. I'm quite adept at AppleScript and have used in and out of QuicKeys and FileMaker. I thought I might end up using it for this and it appears I'll be using it more and more with KM (I'll bet you use a macro for "Keyboard Maestro" -- in fact, I just created one :grinning:).

There are a number of things I need to figure out with Keyboard Maestro, like detecting the state of a button before deciding whether to click, but I don't want to risk topic drift here.

I've got about 300 QK macros to convert. Thanks for your help.

1 Like

Scope out the Pause Until action with a button condition.

-Chris