Conditional Trigger Key Check Using the Variable, Not Modifier Press

Hi there,

I use an eclectic mix of macros to manipulate my Finder/app windows. And in particular, I am using the shift key to determine whether I need to do something for a window on my internal or external screen. Say I want to centre a window on my external monitor or Macbook display: If I use shift in my trigger, I want it on my Macbook display. No shift, then I want it on my external monitor.

Now, additionally, I have set up Finder triggers such as opening the "Documents" or the "Utilities" folder so that I can manipulate these as well through a "Trigger Macros by Hotkey" action. So, as an example, I open up the "Documents" folder, then use the hotkey for centring the window afterwards. Like so:

I know I could change this quickly, but I also want to learn more about KM: The trigger for opening the Documents folder contains a shift (Command-Shift-D). This is a problem because when I trigger the other macro for centring the window, then it interprets the shift key if I use the "If these modifiers are pressed"-condition check:

So the initial macro sends the shift key across to the other macro; thus, the window will always try to be placed on my internal (Macbook) display.

Is there a way to test if the TriggerValue contains the shift key? I have no clue as to how to enter this into the text field of the action:

As I said, I could simply change the initial trigger, but it would be nice to know if this is doable.


Bella Massimo,

A rough solution might be using a temporary "Display text" action with "%TriggerValue%", and copy the Shift character.

Here it is anyway: ⇧

For what it's worth and as far as I know, if you've got multiple macros with the same hotkey %TriggerValue% won't work.

Thank you, @freewind1974! I tried it, but that doesn't work, I'm afraid… Now the shift key is blissfully ignored by KM :slightly_smiling_face:

I would be glad if anybody could hint at using the TriggerValue method. It is a bit of a hack, and I wish the other way could be used, but I can pause until the modifiers change before manipulating the window. This will not always work depending upon which modifier key I release first – I might still have shift pressed down when the action continues on. But it may be an intermittent solution for now.

It always helps if you post your actual macro, rather than images of it. For example, the image suggests you are trying to test for the shift key in a variable TriggerValue -- did you ever set that to the value of the %TriggerValue% token?

I don't think it does. The "If modifiers are pressed" condition checks to see if keys are pressed, and cares not about the trigger used. My guess is that your macro runs fast enough that KM gets to that action before you've released the keys. Easy enough to test -- add a 1 second pause at the beginning of the macro to make sure you've time to release the Shift key.

That may not be acceptable in the "production" version, but it's going to be quite tricky to find a way to consistently detect "I've stopped using the keys to trigger the action, so anything down now is a modifier" -- a "Pause until Command key is up", for example, will depend on you always lifting off the Shift key before releasing the Command key if you don't want the modifier active.

But post both your "New documents window" and the "centre window" macros so people can see what you are trying to do and run some tests on potential solutions.

1 Like

My goodness. You are right. I didn't post the macros since I would presume it would have been too much of a mouthful for anybody to decipher. But I should have; I realise this now. I misinterpreted the %TriggerValue% - it should have been set to text for me to read it correctly, as @freewind1974 suggested. I was presuming that the variable could be used directly. So now it is all working. Thank you for your pointers, @Nige_S!


In KM terms, %TriggerValue% is a text token -- not a variable.

Subtly, but importantly, different -- but since both are used a lot in KM macros their use is worth getting your head around.