[applescript] Suspend/reanimate Applications

Colonel_Panik

Registered
Description:
Some applications do not have a pause button. They take CPU processing power and will not let it go until their job is finished. Other applications (particularly browsers) tend to have pages that will continue to process or refresh in the background, even when the browser is hidden. Apart from quitting these applications, there is another solution: Using the kill -STOP command via the Terminal.
If you open Activity Monitor, you will notice that the suspended application is now taking 0% CPU power, freeing up the CPU.

[GALLERY=media, 9]Applescript-CPU by Colonel_Panik posted Aug 10, 2016 at 10:42 AM[/GALLERY]

How to Use:
Run the script. Enter the full name of the application (as it appears in the Applications folder). Pressing OK will hide and suspend the application.
At this point, clicking the application icon in the dock will not do anything. The application will be unresponsive until it is re-animated.
To reanimate, run the script and enter the full name of the application that is suspended.

[GALLERY=media, 10]Applescript-suspended App by Colonel_Panik posted Aug 10, 2016 at 10:42 AM[/GALLERY]

Modifications:
The app has one entry method: A dialog box asking for the name of the application. The script itself has the option of three different input methods. Text entry, choose from buttons, choose from list. Basically, if you are regularly suspending one or more applications the second or third inputs will be quicker, with no need for typing. You can then save that configuration as an application, or put it in the scripts folder in the menu bar (which is where I put it).

Other Notes/Warning:
• As with any Applescript app, sometimes the dialog box gets hidden behind other windows.
• The script will warn you if you try to suspend the Finder or the Dock. Use this at your own risk. I've included error handlers and a 'copy' button for the Terminal command should the script fail.
• If you suspend an application, and then later try to restart/shut-down, the system will notice the suspended application and see that it is unresponsive. This will throw up the 'Force Quit' dialogs. To avoid this, reanimate the application before restarting/shutting-down.

[GALLERY=media, 11]Restarting-1 by Colonel_Panik posted Aug 10, 2016 at 10:42 AM[/GALLERY]
[GALLERY=media, 12]Restarting-2 by Colonel_Panik posted Aug 10, 2016 at 10:42 AM[/GALLERY]

Any questions/suggestions/bugs, reply here.
 

Attachments

  • Suspend or Reanimate Application.zip
    93.9 KB · Views: 4
Can you tell me what circumstances that a user would need to suspend an application as opposed to quitting the application?
Do you have a a system of reminders that the user has suspended an app?
What happens to the suspended app if the user forgets that the suspension was done and a restart to the computer was done?
 
Can you tell me what circumstances that a user would need to suspend an application as opposed to quitting the application?
Do you have a a system of reminders that the user has suspended an app?
What happens to the suspended app if the user forgets that the suspension was done and a restart to the computer was done?
Sure.

Circumstances:
Some applications do not have a pause button, and they will take as much CPU time as they can when running. Well-written apps, such as Handbrake, have a 'Pause' button, and you can pause the app while you do other stuff. But an app like Screenflow (v4) has no pause, and if you are exporting a file, it will use all the CPU it can, leaving your mac laggy and sometimes unresponsive. If you quit the application, you've lost the file that was exporting (and exporting can take hours).
Similarly, all browsers nowadays let hidden windows and tabs run in the background. If you have 10+ windows with 50+ tabs open, then the browser can take a significant amount of CPU. Although the browser remembers all of the tabs, quitting it means having to wait when it's restarted for all those tabs are reloaded. On a slower system (like mine) this can take 5 to 10 minutes meanwhile the system is unresponsive.
This script allows you to pause such applications.
It's also good for quietening all other apps, if you want to temporarily run a CPU intensive app.

Reminders:
I considered adding this functionality. It is possible with AppleScript to write information to a file that can be reviewed by the script, however, it is significantly more work because there are so many more scenarios to consider. As the script stands, it will check the status of the entered application. If you enter the name of an application that is suspended, the script checks the app status, sees that it is suspended, and reanimates the application. I'm not sure how I'd implement a reminder strategy.

Restarting:
When the user tries to restart, the system tries to cleanly shut down all running apps. When it comes across a suspended app, it will get no response and will alert the user that this application is not responding, and offer the user the option to force quit the application. At this point, it is trivial to run the script again and reanimate this app. If the user chooses to force quit the app, then any unsaved changes will be lost.
Applescript no longer has logout hooks. If it did, then the script could be called by the system on restart/shut-down and then find suspended apps and reanimate them.

There are warnings in the script comments about this.

If I make a proper Mac app, then reminders and automatically running on log out will be part of the specs.
 
Actually, I've just played with some code and I could save the app as an 'always open' app. Then when the user quits the app (or the system quits the app), it could reanimate the suspended apps. That would require writing to disk, but it's possible. I'll need to do some testing, but I'll update the post if/when it's done.
 
Back
Top