1
Apr

Automator and AppleScript

   Posted by: Kertap   in Development

Loooonnnng time no talkie.

I’ve been busy. Sometimes I’ve been busy working on a new website. I might try and post stuff to do with this new site on here in an effort to share the stuff I’ve learned.

To that end I give you a basic AppleScript that other developers may find useful and a slightly less basic Automator script.

The Apple Script

The site I am working on is done with PHP and since I’m too lazy to look for a debugger I’ve taken to writing text to a log. I got a little bored and I wanted a one click solution to opening up the mac os x terminal and tailing the log so I whipped up this little AppleScript.

tell application "Terminal" activate do script "tail -f ~/Documents/Workspace/OnlineHold/logs/debug.txt" end tell

This is probably too much information for most people who read this blarg but it’s a fairly simple deal. It opens the Terminal and then tells it to execute the unix command “tail” on the debug.txt log file. What this does then is scrolls the log file down the screen as text is written to it. It looks very matrixy to the uninformed.

The Automator Script

In another effort to dodge working on the site I’ve spent the last few days playing around with automator. I wanted to automatically download a wallpaper image of the internet and use it as my desktop image.

The first thing I needed was to find a site which would update regularly with images. I found the site InterfaceLIFT which seems to update regularly.

With that done I used an article on downloading and setting wallpapers using Automator as the basis for my workflow.

Unlike in the first article I didn’t want to download every image. Just the latest. In order to accomplish this I used the handy firefox plugin firebug to figure out how exactly the wallpaper site built there image links. I found that each image link had an ascending five digit id associated with it in the link and that the latest image had the largest id. In order to take advantage of this little fact I wrote a brief perl script.

$max = 0; $latest = ""; foreach (@ARGV) {

print "$_\n";

$_ =~ m/[0-9]{5}/g;
if ($& > $max) {
    $max = $&;
    $latest = $_;
}

} print $latest;

This little piece of magic got me the latest image off the page, which was downloaded to a folder and then set as the background.

I was getting the workflow to run every hour but it if it runs it takes over the focus so instead I just execute the workflow when i turn my computer on.

Here it is if you want it. Download and Set Wallpaper disk image

Update: Poking around the interface lift site led me to a page that contains random wallpapers. I’ve changed the script to use this as it means that when the script is run you always get a new wallpaper.

This entry was posted on Tuesday, April 1st, 2008 at 5:54 pm and is filed under Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment

Gamerism – Nerdlife! is Digg proof thanks to caching by WP Super Cache