How to stop computer from sleeping during a long script?

I have a long script on a machine and if the script runs after waking the machine, it will go back to sleep before the script is finished.

I do not want to set the sleep timer to longer.

I am not sure if I go about it in the right way, but I thought of setting the Energy Saver to longer before the script and back to short at the end. Problem is it wants a password and so cannot run unattended.

Is there a way of storing the password in the Keychain?

Here is the script:

do shell script "pmset sleep 0" with administrator privileges
-- long and slow script
do shell script "pmset sleep 14" with administrator privileges

looking forward to suggestions, thanks.

Check out Jiggler:

Thanks will test later when back at machine. looks promising.

I suggest you to adjust
-parameters in the save -energy panel of system prefs
or to download this free software:

I’ve been using Jiggler for eons, but must say that Caffeine is neat too and has a small enough footprint to leave it running.

Thanks cwtnospam

will check this too.

Thanks Adam for adding your experience, always helps.

I now solved it by using Jiggler. thanks everybody!

Just FYI…

The pmset argument force lets you set the sleep without needing the password,

" tells PM to immediately activate these settings. Does not write
them to disk, and the settings may easily be overwritten…

Which means also on restart or logout the these temp settings
are dumped and the real settings in the plist (prefs) are used on login.

do shell script "pmset force sleep 0"

do shell script "pmset force sleep  14"

Nice find, Mark. That and the touch argument will come in handy. Never noticed them before – are they new in Leopard?

Thanks Mark!

Its in 10.4

But Nice find yourself, I never noticed the touch argument before.

Caffeine is now scriptable, which may be a better solution than changing preference or touching files. It can be set to not allow sleeping when starting the script, and then set to allow sleeping when the script finishes. That way if you want to change your sleep settings overall you only have to change the preferences, not the script(s).

Caffeine should do the trick - almost the best app ever (right under Quicksilver) :smiley: