Saturday, September 19, 2009

Schedule a Job by using Terminal Command at

I read a blog on 100 Mac tips and tricks. One of them is the command "say". Basically, you can type in any text or cat a file and pipe output to say. Then you will hear your Mac speech reading the text out. I played this one with several text and text files. It was very interesting. Then I had a thought: can I schedule the speech command to some time later? I remember that in UNIX you can run a command or job by using at command. I immediately tried to use at to schedule a speech. But I failed to do it.

Quickly I found that Mac by default disabled the at command. What I needed to do first was to make at enabled. From Stackoverflow, I was redirect to, from developer's web page to computer user web page. There I got the following answer, using command lauchctl to enable at:

$ sudo launchctl load -w /System/Library/LaunchDaemons/

where sudo is to run a command as supper user; launchctl as an interface to run launch to load daeamons; and -w is used to override the Disabled key (in plist) and set is to false.

Just for sure, I rebooted my Mac to give my first try by the following command:

$ at now + 1 minute
say 'Hello, World! This is a scheduled announcement by at command.'

where <EOD> is Control+d key for marking end of doc. After one minute, I heard the announcement from my Mac. Then I tried another command:

$ at now + 1 minute
rm test.txt

This is a command to remove test.txt file in the current path. As scheduled, I confirmed the remove: test.txt file in the current path was gone.

According to the manual of the command at, it is used to run a specific job in a separate process group with no controlling terminal. More information about this command can be found by using man:

man at

For example, -l option is used to list the current scheduled jobs. "atrm job_number" command is for removing a job.

No comments: