• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: iTunes programming question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iTunes programming question


  • Subject: Re: iTunes programming question
  • From: has <email@hidden>
  • Date: Wed, 12 Jul 2006 00:10:39 +0100

Philip Lukidis wrote:

 if you know how to construct an AE
and you know the application's scripting interface, putting the two
together is straightforward.

It's often the case that documentation of that specificity is lacking. But like you say "reverse engineering" some Applescript with a dictionary into AE shouldn't be too hard as soon as I have a handle on AE (which I'm learning about at this moment).

The HTMLDictionary app on my site will dump aete data to a human readable plain text file.



This script simply gets some basic information for each track in the main iTunes library (~3200), but it nevertheless takes 38 seconds to execute on a dual G5 with 1 GB of RAM. I'm not sure if sending AE messages would trim this down. We'll see.

Like I say, AS is fine performance-wise at sending and receiving AEs; it's when you use it to crunch large amounts of data that it gets dog slow. I'm guessing you're writing OO-style code, getting a list of track references then iterating over this and getting the desired properties of each track. e.g.:


set trackinfo to {}
set tt to GetMilliSec
tell application "iTunes"
	set trackslist to tracks of library playlist 1
	repeat with trackref in trackslist
		tell trackref
			set end of trackinfo to {name, artist, album, time}
		end tell
	end repeat
end tell
(GetMilliSec) - tt -- (0.65 sec for 100 tracks)


This is a horribly expensive way of doing things. You're sending thousands of events and iTunes is having to create and resolve thousands of object references to get the data you want. The trick is realising that what you're actually dealing with is an RPC + first- class query mechanism, not an OO API as you might think. (AS syntax looks object-oriented, but it's all just syntactic sugar. Fools everyone.)


A single 'reference' (query) can identify multiple objects, allowing a single command to operate on all of those objects at once (assuming the application implementation supports it; some are better than others in this regard). Thus to pull the same info (albeit in a different order) from iTunes by constructing just four queries (name of every track of library playlist 1, artist of every track... etc.) and sending four 'get' events:

set tt to GetMilliSec
tell application "iTunes"
	tell every track of library playlist 1
		set nameslist to name
		set artistslist to artist
		set albumslist to album
		set timeslist to time
	end tell
end tell
(GetMilliSec) - tt -- (0.02 sec for 100 tracks)


I'm prototyping some very basic AS scripts right now, but soon I will have to start reading the AS docs/book. Since so far I have not seen other scripting languages giving iTunes control support, I'll have to stick to AS/AE for now.

As I say, the appscript package on my site adds high-level application scripting support to Python. I'd recommend taking a look just for chapter 2 of the appscript documentation, which provides a nice summary of how this application scripting stuff really works. There's also Mac::Glue if Perl is more your fancy. Ruby's support is currently very basic, but hopefully will be up to snuff before too much longer.


HTH

has
--
http://freespace.virgin.net/hamish.sanderson/


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >RE: iTunes programming question (From: "Philip Lukidis" <email@hidden>)

  • Prev by Date: RE: iTunes programming question
  • Next by Date: Adding a property value to a plist file
  • Previous by thread: RE: iTunes programming question
  • Next by thread: RE: iTunes programming question
  • Index(es):
    • Date
    • Thread