Hi i’m trying to figure out if there is there any way to set if/then triggers based on which app was opened/used/in the front most recently. Could you please help?
I have a midi-triggered scroll macro set to trigger with an if/then condition based on whether evernote in at the front or not. I set it up like this because i sometimes use the scroll macro with Scrivener instead of evernote. It works great, but sometimes get confusing if i was working in evernote but then go to change a song in iTunes on my other monitor then i hit the button and it opens Scrivener instead bc evernote technically wasn’t in the front anymore- iTunes was.
So I’m wondering- Is there any way to set if/then triggers based on which app was opened/used/in the front most recently? That would solve all of the confusion.
heres a screenshot of the macro and the options i see :
The usual approach is to put the macro in a Group that is activated ONLY when a specific app is frontmost.
You can use the same trigger in macros in different groups.
So, have different Macro Groups for Evernote and Scrivener. Then the midi-trigger would trigger one macro when Evernote is frontmost, and a different macro when Scrivener is frontmost.
Also, at some point I disabled the second part of the macro ("otherwise execute the following actions") and decided to separate if/otherwise scenario into a different macro (you can see the disabled actions below, as well as the other 3 macros in the middle pane for scrolling up and down in both evernote and Scrivener) . This was a few months ago, so im not sure why i did this now, but must have been having some sort of issue, sorry that this is such a mess lol! Could you please advise on whether its better or makes a difference if i recollect the if/otherwise scenarios into one macro or leave them in multiple macros?
The point of the "track target application" macros is to set a TargetApp variable, so it's this variable that you want to use to determine how your macro behaves. In cases like this I would actually recommend not using If/Otherwise at all, but a different action called Switch/Case which can be used to have your macro perform many different actions based on a single condition. This also makes it possible to consolidate the functions of multiple macros into a single macro. Here's an example that should help get you most of the way there:
As you requested in your OP, this macro will open either Scrivener or Evernote depending on which one was opened last before scrolling the front window down, and it determines this by looking at the current contents of the TargetApp variable, which is of course set by the most recent of the two apps to have been used. You should be able to duplicate this macro and change the scroll action and triggers to have it do the same thing for scrolling up, and of course the same "do different actions depending on which app was last used" principle can be used in any other way you like.