Samuel Sjöberg's weblog

Skip to navigation

My first AppleScript

My posting frequency has dropped to a new low between this and the previous post. It has come to the time where I feel obligated to write something, actually anything will do.

Lately I've been working on a project on UCIT. Unfortunately I can't tell what it's about, but I can tell that my work included developing a HTML mockup for a website. I got an opportunity to learn a lot more about AJAX techniques and (unfortunately) discovered how much headache that can be caused by browser quirks.

The work is now finished and I'm going to spend the rest of the summer defining and refining my master's thesis project. I plan to set up a separate blog for this, but more on that later.

And now something completely different

I have played around a bit with AppleScript which I think is extremely powerful and funny to experiment with. As a first step to a iTunes launcher where you'd click on a album artwork to play the album, I wrote the following AppleScript.

on run argv
   set pattern to ""
   repeat with y from 1 to count argv
      if y > 1 then
         set pattern to pattern & " " & (item y of argv)
      else
         set pattern to item y of argv
      end if
   end repeat
 
   tell application "iTunes"
      copy (a reference to ¬ 
         (playlist "Library")) to lib
      copy (a reference to ¬
         (playlist "AlbumTracks")) to albumTracks
 
      delete every track in albumTracks
      tell albumTracks to set shuffle to false
      duplicate (every track of lib whose ¬ 
         album is pattern) to albumTracks
      try -- Only play if songs are found
         play albumTracks
      end try
 
      return pattern & ": " & ¬
         (count every track in albumTracks)
   end tell
end run

(¬ just indicates that all should be written on the same line, i.e. a wrapped line.)

To run it, open Terminal and write the following (where you replace
iTunesLaunch.scpt with whatever you chose to call your script):

%>osascript iTunesLaunch.scpt Album name

So the neat thing here is that the AppleScript is run from the terminal. Now I only have to come up with a clever way to use this idea in combination with slideshow or something similar.

By the way - all credit for the album launcher idea goes to David Werjefelt.

To finish of this unfocused post, just let me say - I'll be back. With a more focused post on my first actual bookmark and possibly a word or two on something I call NavigationAid (also a bookmarklet-kinda-thingy).

Pages linking to this entry

Pingback is enabled on all archived entries. Read more about pingback in the Pingback 1.0 Specification.

About this post

Created 25th July 2005 01:07 CET. Filed under Blogging, Mac OS X.

0 Comments
0 Pingbacks