Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How does one go about scheduling "settings" to change on applications given certain criteria? For e.g., I am using Adium, and between the hours of 8am and 5pm, I would like that status to set to "Available", and outside of these hours go "Invisible" or "Away".

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

The easiest way to do this is via Applescript. The commands you need are both single line. To make Adium go online the Applescript code is:

tell application "Adium" to go online

To make it go invisible, the Applescript code is:

tell application "Adium" to go invisible

Pretty simple. You can also tell Adium to go away. Open the Applescript Editor App in your /Applications/Utilities directory and create two Applescript files; one has just the command to go online and the other the command to go invisible/away. Save them as .scpt files with appropriate names.

That was the easy part. The next question is how do you trigger the right script at the right time? You essentially need to create the following two scheduled tasks:

"run adium_invisible.scpt at 5pm everyday"

"run adium_online.scpt at 8am everyday"

The default way to do this, built into OS X, is to use the UNIX 'cron' daemon. It's documentation can be found here. If you find the cron interface intimidating, there is a GUI app you can use to set tasks up, called Cronnix.

You'll still need to understand the timing syntax that crontab files use though. Wikipedia can get you up speed on that. Inside your user crontab you want to create two scheduled tasks. They should look like this:

0 8 * * * osascript path/to/adium_online.scpt

and

0 17 * * * osascript path/to/adium_invisible.scpt

osascript is an Apple specific command that lets the shell call and run an Applescript. You give it the path to the .scpt file as a paramater. Once you have the two cron tasks set up you should be good to go.

If editing the crontab file by hand, and not using Cronnix, don't copy and paste these verbatim, as tabs are required between the hours, minutes, days etc., not spaces as I have here.

Also, you could create cron tasks that use osascript and pass the Applescript directly like this:

osascript -e 'tell application "Adium" to go online'

However, storing the Applescript commands in a separate file gives you flexibility in the likely event that you need to change what commands get run later on. You can add to or remove from the .scpt files without needing to interfere with the crontab file.

share|improve this answer
    
Thanks @Vickash. This is very helpful. A quick follow up: How do I discover all the commands that are available to an application? E.g., tell application "MyApp" to take action x –  KM. Nov 21 '11 at 15:59
1  
In AppleScript Editor, File > Open Dictionary. –  Vickash Nov 23 '11 at 1:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.