Double Tap to Open Two Finder Windows Using a Stream Deck

Hi, I am using a Stream Deck to assign macros to. (Great btw.)

I have a key in Stream Deck that triggers a macro created in Keyboard Maestro to open a Finder window.

I am now trying to create a macro assigned to the same key that on DOUBLE tap of that key it opens a second Finder widow.

Been trying for a while, but can seem to crack it. Any help greatly appreciated.

Thanks
Martin

Try a multipress macro, for example the one from @noisneil

Hi Frank,

BIG thank you for this, but WAY beyond my comprehension when looking through these.
I had a look at your Hotkey / USB Macro.. and well....my mind just fogged over.. :slight_smile:

I am not a programmer by any stretch of the imagination. I have set up 25-30 simple triggers to open applications or close applications, open some windows and the like. All those seemed pretty easy.

I think in all honesty I need a basic course to start with and then move on to this more advanced level.

Again, big thanks for trying to help

It looks intimidating, but it's much easier than you think :grinning:

You just have to replace the red parts with your actions. You don't have to pay attention to the rest.

If you want a "built-in" solution, this is only possible with short/long press, as far as I know.

Here is a simple example with the trigger "a". This is just an example, of course you lose the "a" if you set it up like this.

a short = Finder

a long = safari

Thanks for your help, appreciated :slight_smile:

I will have a work through it tomorrow (I am in NZ and its getting late here) as I would like to better understand.

Martin

Mmm okay, so there are four actions I have to change...

Can you give me an example, say of the first one so I can then work out the rest please.

I think the "display' thing is confusing me.

I have deactivated and replaced the "red actions". (Only as an example)

Single press = open Finder

Long press = open Safari

Double press = open Scrivener

Hi, I think I may have confused you and in turn confused myself by then trying to work out what you sent over relative to ONE application, IE Finder.

The macro I require is ONLY to open TWO FINDER windows. No other applications as I have them sorted.
One press I now have working opens the one finder window. If I press that button again nothing happens of course because a finder window is already open. I was trying to make it so that if I double tap the finder button that I have already set to open a finder window, it would just open another finder window.
Apologies for the confusion

If you want a specific window to move to the front, try the action

image

You just need your original macro, but using an "If... Then... Else..." action. In pseudocode:

if Finder window A is open
   open window B
otherwise
   open window A
end

That means you only have to single-tap the button to either open A or, if A is already open, B. If neither is open you could double-tap to open A then B, but you'll probably want a "Semaphore Lock" so that the instance triggered by the second tap doesn't run until the one fired by the first tap has completed.

Have a go yourself, but if you're still scratching your head after 10 minutes post your macro and say what you're stuck on.

Having a practically ZERO logic brain... I can't work out a logic puzzle if I am given the answer and then try to work it back.. I am NOT kidding) Thankfully we have great logical minds on the planet otherwise we would be in a sorry state :wink:
Anyway, I was just about to spit the dummy and just pay someone to do this (I hadn't out of embarrassment done that earlier) when I thought about asking CHAT GP to solve this for me.
This is what it had to say:
To open a second Finder window using the code you provided, you can modify the existing macro in Keyboard Maestro. Here's how you can incorporate the code into the macro:

  1. Open Keyboard Maestro and locate the macro you created for opening a single Finder window.
  2. Edit the macro by clicking on it.
  3. Add a new action by clicking the "+" button below the macro editor.
  4. In the search bar, type "Execute an AppleScript" and select it from the list.
  5. In the AppleScript action panel, enter the following code:

applescriptCopy code

tell application "Finder"
    set windowA to exists window 1
    if windowA then
        make new Finder window
    else
        make new Finder window
    end if
end tell

This code checks if the first Finder window (window 1) is open. If it is open, a new Finder window (window B) will be opened. Otherwise, if the first window is not open, a new Finder window (window A) will be opened.

  1. Save the macro.

Now, when you trigger the macro (e.g., by tapping the assigned key on your Stream Deck), Keyboard Maestro will open a Finder window. If a Finder window was already open, it will open a second window. If no Finder window was open, it will open the first window.

Please note that the code assumes you are referring to the first Finder window as "window A" and the second Finder window as "window B" based on your code snippet. If you have different window names, you can modify the code accordingly.

I worked right out the box
CHAT GP it seem might just be my guiding hand that assists my non logic brain.
BIG thanks for all the help I received. I appreciate just how hard it must be to explain logic to different type of brain .... LOL

Discovered a bit of a bug in that last one. Went back to CHAT GP and asked it to give me code that worked in latest version of Keyboard Maestro (I have Ver 10.2 )
It came back with the following, which now works perfectly :slight_smile:

The only question now is...... Does this make me a 'programmer' ... LOL

Here are the instructions from CHAT GP
Here's an updated set of steps using commands available in Keyboard Maestro version 10.2:

  1. Open Keyboard Maestro and locate the macro you created for opening a single Finder window.
  2. Edit the macro by clicking on it.
  3. Remove the existing action that opens a Finder window.
  4. Add a "Set Variable" action by clicking the "+" button below the macro editor.
  5. Set the variable name to something like "WindowCount" and the initial value to "0".
  6. Add an "If Then Else" action by clicking the "+" button below the macro editor.
  7. Set the condition to "Variable WindowCount equals 0".
  8. Add a "Display Text" action inside the "If Then Else" branch by clicking the "+" button below the "If Then Else" action.
  9. In the "Display Text" action panel, set the text to something like "Press again to open a second window".
  10. Add a "Set Variable" action below the "Display Text" action by clicking the "+" button below the "If Then Else" action.
  11. Set the variable name to "WindowCount" and the value to "1".
  12. Add another "If Then Else" action below the "Set Variable" action by clicking the "+" button below the "If Then Else" action.
  13. Set the condition to "Variable WindowCount equals 1".
  14. Add a "Display Text" action inside the new "If Then Else" branch by clicking the "+" button below the new "If Then Else" action.
  15. In the "Display Text" action panel, set the text to something like "Opening a second window...".
  16. Add a "Execute an AppleScript" action below the "Display Text" action by clicking the "+" button below the "If Then Else" action.
  17. In the "Execute an AppleScript" action panel, enter the following AppleScript code:

applescriptCopy code

tell application "Finder"
    make new Finder window
end tell

Now, when you trigger the macro (e.g., by tapping the assigned key on your Stream Deck), Keyboard Maestro will open a single Finder window. On the second press, it will display a message and set the "WindowCount" variable to 1. On the third press, it will display another message and open a second Finder window.

Please note that the actions in this updated set of steps use commands available in Keyboard Maestro version 10.2.

Ah -- good. You've found the obvious stupidity in ChatGPT's first answer -- it didn't matter whether or not a window already existed, it always made a new window.

Except it doesn't. Compare what it does to what you originally asked for and you'll see it doesn't do that! Now there's nothing wrong with changing the requirements to meet what the macro does, and it may even be that what the macro does is actually what you intended all along, but that points to a deeper problem...

Being a "programmer" starts with being able to explicitly define your problem, as completely as you can. That isn't usually a single-step process but it is very important -- even if you then ask ChatGPT for the answer (or ask on this Forum) it should be pretty clear that the answer you get very much depends on the question you ask!

In your OP you imply that a single tap on the SD key should do nothing if a Finder window is already open -- otherwise there would be no need for a double-tap, you can just open a new window with every single tap. But perhaps you want to stop at two windows and any further taps to be ignored?

So I'd urge you again to think your problem out fully and then ask again. A really easy way to do this for KM macros, since we're often trying to automate a manual process, is to do that process by hand and to note down every step you take and every decision you make. You want to be as complete and precise as possible -- computers are dumb and often need to be told things that we think are blindingly obvious...

That's not true -- you use "logic" all the time in your daily life. You may not formalise it in a way that'll help you write a macro, but that's just a matter of practice. For example, after you've poured milk on your breakfast cereal:

"If the milk carton is empty I rinse it and put it in the bin, otherwise I put it back in the fridge."

...becomes, in pseudocode:

if carton is empty
   rinse carton
   put carton in bin
else
   put carton in fridge
end if

That seems a really silly example -- but it's the basic form of the "If... Then... Else..." action in KM:

...and more complex logic is just a question of building on that.

I'm firmly convinced that if you can just demystify the whole "writing a macro" thing you'll be up and running in no time. So have another go, starting from scratch with a blank piece of paper, work out your requirements, turn that into a series of steps, try and make those into a macro. Post here if you need help, or contact me privately if you'd prefer.