Need some Help? Have a tip to share?

Email me at MacTipper@gmail.com, or, leave a comment!

Learn How to Win Free Stuff Online


6/18/08

Run An Applescript Every Day At 5 AM [System]


RSS Subscribers: There is a video for this post.

Yesterday, I wrote about scheduling your mac so that it sleeps after you go to bed, but wakes up before you get up. If you combine this with a very simple applescript, you can automate your entire computer morning routine. We'll be using Lingon to create a daemon to run this applescript every day at 5:00 AM.

At the end of this tip, you'll have an applescript that runs at 5 AM and will open up some links and check for any new emails.


Step 1: Download Lingon. (Make sure that you download the version applicable to your computer system.)




Step 2: Open up the Lingon application. (I would suggest moving it to your applications folder, but, that's not required.)


Step 3: Click the "New" button in the upper left corner of the Lingon window.




Step 4: Select the "My Agents" radio button and click the "Create" button.




Step 5: You should be presented with a window like this:




Step 6: For "Name" type in: "com.yourname.morning.routine". Replace "yourname" with your first name. We do this so that you have a unique identifier for your daemon.


Step 7: Now for the "what". Open up the applescript editor found at Applications > AppleScript > Script Editor.app (Or, do a spotlight search for "Script editor".)

Script editor looks like this:




Step 8: Our applescript is going to check for new mail. It's also going to open up a couple of websites. To open up the Mail application and check for new mail, type (or copy and paste):

tell application "Mail"
run
check for new mail
end tell


If you want to open an application besides mail, use:

tell application "App_Name" to run

Once again, replace "app_name" with the name of the application you want to open.


Step 9: To open up a link, use:

open location "the_url"

Obviously, replace "the_url" with the url you want to open. You can duplicate this as much as you want so that you open multiple URLs:

open location "http://www.mactipper.com/"
open location "http://www.comics.com/comics/pearls/"


You'll probably want your computer to delay 20 seconds or so before it does any of this. That way, it has a chance to connect to the internet. To do this, add "delay 20" to the very beginning of the script.

Your applescript should look similar to this:




Step 10: Now, we need to run the script to make sure it works. Hit Cmd-R and mail should open up and check for new mail, TextEdit should run, and your default web browser should open up the URLs you added.


Step 11: Save you applescript. I would suggest you save it in your documents folder and call it "morning.scpt".




Step 12: Now that you have your applescript, open up the application Terminal. (Found at Applications > Utilities > Terminal.app. Or, do a spotlight search for "terminal".)


Step 13: Once Terminal has opened, type (or copy and paste):

osascript

Then, find your applescript in Finder and drag it to the terminal window. It should look something like this:




Step 14: If you hit return, your applescript should run. If it does, then copy the text from Terminal.app and paste that text into the "What" field of Lingon.




Step 15: For the "When" section, check the box next to "At a specific date:". Then, make sure that the drop down menu says "Every Day" and the time section is set to sometime in the morning.




If you set the time section to a time that your computer is asleep, then the script will run when your computer wakes up. So, even if your computer wakes up at 8 AM, setting it to 5 AM guarantees that if you get up early, the script will still run.



Step 16: Your Lingon window should look like this:




Click on the save button, or hit Cmd-S. This will save your daemon. You can now quit Lingon. (Cmd-Q)




Step 17: The final step is probably the easiest. Log out and log back in again. When you do, this will "prime" the daemon so that it runs at the time you set.



While having your computer automatically open up some links and applications in the morning is handy, there are other uses for Lingon. One example would be replacing folder actions with LaunchD.

If you would like a visual demonstration of this tip, or want to read a few good jokes, watch the video for this post.

0 comments:

Post a Comment

Subscribe Via Email!

Enter your email address:

Delivered by FeedBurner