Applescript – Quit or Launch Application script.. ( Revised )

In my  previouse  post :  Applescript – Quit or Launch Application if another is or is not running

The script was limited to one master app. The one that if running or not  determines if the slave app launches or quits.

This new script allows you to add as many apps to the master app list and also to the slave list.

So far so good but there are some other things about the app that I have taken into account.

  •   I noticed that even with the  do shell script  “kill -15 ” &  appToKillID . line.

  A app that was supposed to be killed looked like it had but its process was still  running.
Not good.
So I have changed it to the normal and correct way of quitting an app.
tell   application   this_App_to_quit   to   quit
  •  Since  I have stopped using the  killall  command.

I do not need to get the process ID’s. so that is removed. I now just check if there is a result from the System events process search. And set a true or false boolean to a variable. Which is checked later.

  •  In the previous post, I also show how to make the app run from a Launch Agent.

This is all well and good but what happens when I want to run the slave apps by their selves without the master apps running.

I have now  written a simple script that I can place in the Applescript Script Menu.
The new script will do two things.
  •  It will change its name to either  or  Dsiabe_Dual_Apps.scpt  depending what the current name of the file is.  This then give me a way to see the status of the Launch Agent. Enabled or Disabled.

  • This script will also load or unload the Launch Agent.  T here is no checking if the Agent is loaded or not. For my purposes I do not think there is a need.
So first the revised script.
 [iframe /blogR/dualApplQuitLaunchCodePostTwo.html 700 800]
————————
In the script replace my app names with yours in  masterAppiDs and  slaveApps
  • set  masterAppiDs  to  {“AppleScript Editor”, “Xcode”} #can be more than one app
The apps that are opened by the user. And are not quit by the script.
  • set  slaveApps  to  {“Snippets”, “TextEdit”} #can be more than one app

The apps that a are told to close if none of the Master apps are running

And here is the Enable-Disable Script.
 [iframe /blogR/enableDisableCode.html 700 455]
To run the Enabel Disable Launch Agent Script:
If you have not already enabled the script menu for Applescripts. The open the Apple Script Editor’s preferences. And check(tick) the Show Script menu in menu bar .
A new  menu bar item will appear.
Click the Script menu and Navigate to : Open Script folder->Open  Users Script folder
Place the  Enable-Disable Script in the Users Script folder that opens up.
Now when you click the Script menu. You will see the script listed in the Script items.
Just select it and it will run. Its name will change to represent  enabled or disabled.



If that all sounds like too much work.

 

Trust me it isn’t.  Then you can just wrap the script in a good old fashioned   idle handler.

Once saved as an Application with the Stay open after run handler checked. 

The app will run every 10 seconds. You can adjust the return in the handler to what ever number of seconds you want.

To disable it just treat it like any old app. Quit it. 🙂

[iframe /blogR/OnIdledualApplQuitLaunchCodePostTwo.html 700 800]

Good Luck.

Hi, Please Leave a Reply