Quitting a Specific Application

In the middle of a macro I'm opening an application. Later in this macro I want to quit that app, but leave others running. I've tried setting a variable using %Application%1% token, but can't find a way to quit %Application%1%. What am I not seeing?

You can't do it that way with the "Quit a Specific Application" action. If you know the application you will be launching in the earlier step, select it from the "Quit..." action's application list. If you don't know (Gulp! There be dragons!) then you could use the "Use Variable" action to activate the app, then use a ⌘Q "Keystroke" action.


Didn't know about the Use Variable action. You be droppin' gems today!

Nah -- I be readin' da Wiki while pretendin' to know what I's talkin' 'bout.



I think I can get that 'Use Variable' to work. I'm working on a macro to clean up my desktop. The application that is launched depends on the file at the time the "For Each Finder Selection" triggers. I'll try to get the file extension using attributes action and go from there. Worst case, I have to manually close apps after the macro quits.

Thanks for help.

It's going to be a bit horrible if you "launch app, quit app" for every file you open. Perhaps start the macro with an empty variable, add every app the macro launches (not activates), and at the end use a "For Each" over the variable to quit the "extra" apps that were opened?

Sorry for the delay. I'm finally revisiting this macro to spice it up.

Love this idea!

Do you mean use one variable name?

Do the additional 'app adds' get appended and then seen during the run thru of the 'For Each'? (an array?)

Having thought about this again, you could run a macro that

  1. Logged the foreground app names
  2. Did your cleanup
  3. Logged the new current foreground app names
  4. Looped through the apps in the new list and
    • If the app isn't in the list from step 1
      a. Foreground the app
      b. Quit it

Proof of concept follows. Launch a few apps, trigger the macro, launch a few more, press ⌘⌥⌃ to unpause the macro and it will quit the apps launched after the macro started.

Quit Newly-Opened Apps.kmmacros (9.7 KB)


If your cleanup takes a while you might forget the macro is running but paused! You could change the pause from a keypress to a KM "Alert" dialog and wait until "Continue" was pressed.

Or you could have two macros, one to log the starting apps into a global variable and another that you ran after cleanup that used the global as the starting-apps list -- for safety you should include a check that cancelled the second macro if the global is empty along with a final action that set the global to empty (just in case you ran the second macro without running the first).

Thank you for this. I incorporated it into my macro and it also helped me understand better what's going on inside a 'For Each Item' loop.