I've been toying around with AppleScript and Automator to get this thing to work, but I just can't seem wrap my head around it. If anyone could show me an example or give me some tips on how I can set an application to close at a specific time and then put the computer to sleep or shutdown, it would be greatly appreciated.
I'm assuming that you'd like to initiate this procedure as opposed to having it run at a regularly scheduled time.
My approach would be to initiate this from the command line, but any commands can be run in a shell script component of an Automator script with some modification. The following approach combines a few components to get the job done:
1. Telling the Application to quit
This can be as simple as:
2. Putting the computer to sleep
Have a look at
3. Scheduling an operation to be run at a specific time
Have a look at the at command. This command gives you the ability to specify a time for a command to run. You'll need to enable this functionality as it is not by default. To enable the
Once you've enabled
which works because
Putting it all together
What follows assumes that
Save that file to
I didn't do any checking to make sure that Mail actually closed. The script also assumes that nothing else is going to get in the way of putting the computer to sleep. I've kept it simple here as a starting point for what you want.
Here's a strictly applescript version that accomplishes this given a hard-coded time value. You could, of course make this part interactive if you want. Also, this version assumes the time-string relates to today.
You can schedule an event once with at:
Or to schedule it to repeat every day, edit the crontab with