Trigger on Application that is running, but in the background


#1

Hi, I’m trying to run an action on Skype, that starts up, runs in the background and then opens a window in the background, but does not activate that window. I would basically like to minimise this window as soon as it pops up. I’ve tried the ‘launches’, ‘activates’, ‘deactivates’ and ‘while application is active’ triggers, and these only work once the Skype window is select i.e. when the window is activated.
Any ideas on how do to this other than creating a macro that’ll loop continiously in the background?

thanks


#3

Unfortunately, I don’t have an answer, but I do have a similar question. I have an application, Papers, running on one computer. I switch to another computer somewhere else, and I want to make sure that Papers is closed. Sometimes I remember to close it, sometimes I don’t. So basically I need a macro that asks:

  • is Papers running
  • has it been inactive for more than 15 minutes
  • then close the application Papers

I can do the third line easily with Quit Specific Application and I think for the first I use a trigger of this application is running. What I can’t figure out is how to test for whether it has been inactive for 15 minutes. Any help would be most appreciated. Larry


#4

Imhinman, I am unclear from your question whether you physically go elsewhere to another computer or use some networked app. If the former, then perhaps you could test for system idle time as suggested here.


#5

Chris,
I’m talking about being physically away from the computer. I might forget to close the program when I am using it at home and then attempt to open it on my laptop at the office, which can have seriously bad results.


#6

Keyboard Maestro has an IDLE() function that tells you how long the Mac has been idle (ie, no user input via mouse or keyboard).

If your Mac goes to sleep, then Keyboard Maestro will not be able to quit anything, so you need to ensure that your Mac stays awake long enough to tell that the Mac is idle enough to quit.

Assuming you want to wait until the Mac is idle 15 minutes, set the Mac to not sleep for at least say 30 minutes, and then set a periodic trigger to run every ten minutes and if the calculation IDLE() > 15*60 is true, then quit Papers.

The CPU/battery usage of such a slow periodic trigger will be negligible, although if you want bonus points, have another pair of macros:

Trigger on Papers Launches, action Enable Periodic Macro
Trigger on Papers Quits, action Disable Periodic Macro

If you want to consider Papers idle if it has not been in the foreground for 15 minutes, even if the Mac is not idle as such, you can add another macro:

Trigger on Papers launches, activates or deactivates, action Set variable Papers Last Used Time to NOW()

And then your periodic macro can first test if Papers is at the front and if so also update Papers Last Used Time, and then test the calculationNOW() - Papers Last Used Time > 15*60 and quit Papers if that is true.


How to create macro activated only after no key pressed
#7

Thanks, Peter. This is incredibly helpful and I really appreciate your taking the time to explain this.
Best,
Larry

Hinman Lawrence M.
hinman.lawrence@gmail.com


#8

Thanks Peter for the idea. I tried to put create a macro with the insight. But have failed to make a working macro.

Imhinman - were you able to make the macros? Would you be able to share the actual macros, or the logic and variables used?

Thanks!


#9

I worked some more on this problem. Still unsuccessful.

I have two macros.
Macro 1 launches when TaskPaper is launched. It works when the computer is idle. The part that is not working is the second if statement.
Macro 2 is supposed to set the variable which is used to assess whether TaskPaper has been deactivated. And this macro works.

I am going to share the macros below. Would be grateful if somebody could identify the mistake that I am making. I think I am going wrong where I do the calculation
’NOW() - %Variable%TPDeactivated% > 120

Thanks!

Macro 1:

Macro 2:


#10

Ok, I think I have it working now. Pasting a version of the macro.


#11

I wonder if someone has been able to answer the original question: How do you send commands to a background window with Keyboard Maestro?


#12

You cannot send commands to any non-foreground application with Keyboard Maestro, except:

  • Using the Select Menu Item action, which will pull the app to the front, select the menu, and then pull the previous application back to the front
  • Using AppleScript/Shell Script, etc

Edit: As of Keyboard Maestro 8, you can send key strokes (Type a Keystroke or Insert Text by Typing actions) to non-foreground applications, though applications may or may not be willing to accept keystrokes when they are in the background.