Applescript

[prev] [thread] [next] [lurker] [Date index for 2005/08/07]

From: peter (Peter da Silva)
Subject: Applescript
Date: 20:19 on 07 Aug 2005
How the hell do I add a file to iTunes using Applescript.

I'm obviously holding my face wrong.

Every example and the documentation says I do something like this:

tell application "Finder"
  set theSelection to selection
end tell

tell application "iTunes"
  set thePlaylist to make new user playlist
  repeat with theFile in theSelection
    set theTrack to add theFile to thePlaylist
  end repeat
  my ps_play_next_ref(thePlaylist)
  delete thePlaylist
end tell

And it comes back with
  Can't make <<class cUsP>> id 42775 of <<class cSrc>> id 56 of
	application "iTunes" into the expected type.

Or sometimes, it tells me Finder doesn't know how to add an alias to (the
same kind of spew).

Well, DUH, I didn't say "tell application "Finder"".

And, by the way, things like "item 1 of blah" are something Grace
Hopper would have come up with. Or maybe it's Larry Wall's idea of
what COBOL should be like. I haven't used COBOL in years, and I
still remember how tired I got of "perform monkey-balls through
smelly-swamp".

How about an Objective C scripting language, Apple? Something like:

tell (application "Finder") {
  theSelection := [selection];
}

tell (application "iTunes") {
  thePlaylist := [Playlist new];
  while (theFile := [theSelection next]) {
    theTrack := [thePlaylist add: theFile];
  }
  ps_play_next_ref thePlaylist;
  thePlaylist delete;
}

Then I wouldn't have to fucking guess how to convince it to use
the right version of "add". God damn, get the basic syntax right,
or at least internally consistent, and worry about frills later.

All I want is that when I'm playing a song, I can cue a newly
downloaded file in iTunes without it changing the playlist to the
library and forgetting that I'm in Party Shuffle, or doing it all
manually.


Generated at 19:00 on 15 Sep 2005 by mariachi 0.52