World According to Jussi

Mar 13 2009

Applescript is as fun as a massacre

I may have communicated my hatred towards AppleScript previously but let’s recap.

AppleScript does not fit the model a programmer’s brain is used to. It has terrible documentation and it seems to just fight against you. Part of the problem is not AppleScript per se, but the application dictionaries, but from the end user’s point of view the guilty party is not relevant, in the end the experience just sucks.

Today I rewrote a script I had written years back, mainly because I had lost the script somewhere. Writing less than 30 lines of easy AppleScript to integrate iTunes and QuickTime Player took more than 30 minutes and was at least as frustrating as it was years back. To help the future me I document some basic things below. They are very easy to read, but much harder to write while fighting the AppleScript.

Get currently playing track in iTunes

set t to current track

Get first of currently selected tracks in iTunes

set t to first item of selection

Get the alias of a track

set loc to location of t

Get the play position (in seconds) of iTunes

set pos to player position

Set the play position in QuickTime Player

-- d is the document, pos is the wanted position in seconds
set ts to time scale of d
set current time of d to ts * pos
Page 1 of 1