How to inhibit suspend temporarily?

A program to keep your computer awake is Caffeine. I would make a .bash_aliases file to also call caffeine when your original code is called.

alias newname="origcode && caffeine"

Depending on which code you are trying to keep your computer awake for, you'll have to make a custom script that includes killing caffeine when the other code is stopped. Some more details about the particular code would help.

Update: A simpler way would be to run xdotool, which can be installed with sudo apt-get install xdotool. You can write a script that is called when your target code is opened and then use the sleep command for 29 minutes and then run xdotool key a or something arbitrary to keep the computer awake.


If

  1. A script in /usr/lib/pm-utils/sleep.d can check if the application is running and return 1 to indicate that suspend should be prevented.
  2. The problem of "the system then gives up on suspending automatically, instead of trying again after another 30 minutes" is solved by moving the mouse which restarts the timer again (I hope I've understood properly what you mean by this)

then why not just jiggle mouse pointer after the application terminates.

To summarise:

  1. Use sleep.d to keep system from suspending.
  2. Write a script that jiggles mouse once.
  3. Call 'Long-running-script && mousejiggle'

This will not hinder the screensaver.

The only problem is that it will be 30 minutes after the process terminates when the system suspends. This is the case with your 'EDIT' solution also.

PS: I was looking for a solution to a similar problem when I learnt of xdotool from this page. So, thanks. Hope this helps.