RSS Feedings
What's New...
30 Most Recent
dougscrptr
Site Menu
[ Home
[ What's New
[ 440 Scripts...
- ...by category:
- Managing Tracks
- Managing Track Info
- Managing Artwork
- Managing Playlists
- Controlling iTunes
- Exporting Info
- Managing Files
- Networking
- Internet
- iPod
- Miscellaneous
- With Other Apps
- Retro Scripts
- Script Stats
[ Download FAQ...
[ Missing Menu Commands
[ FAQ & Solutions
[ Tips & Info
[ Forum at iLounge
[ dougscrptr
[ Twitter
[ my del.icio.us
[ Uhm, Windows?
Shareware Apps
- Dupin v1.3.3
- Join Together v5.2.1
- iTunes Library Manager v5.1
Site Info
- Who's Doug?
The language of AppleScript is similar to our everyday language, and is not at all like unfamiliar and confounding heiroglyphics you may have seen in other programming languages. You don't have to learn too many new "code words". This also makes it much easier to explain. Usually, a line of AppleScript does exactly what it says it will do.
Type this fairly simple sentence into Script Editor and then activate it by pressing the "Run" button:
tell application "iTunes" to play
This is a tell statement; the script "says" to your computer: "tell iTunes to do something"; in this case to start playing (the first track in the "Library"). Tell statements contain objects and commands, very much like nouns and verbs, respectively.
When you want to perform several commands on several objects, you can use just one tell statement:
tell application "iTunes"
set sound volume to 40
set EQ enabled to true
play
end tell
The end tell at the end encloses the command statements. Sometimes this is called a compound tell statement or a "tell block". Usually, all of a script's commands and computations occur within just one set of tell statements (there are exceptions).
To specify a particular object, you must infer its relationship to the tell object, in our case, iTunes. Look:
tell application "iTunes"
play track 13 of user playlist "Sparkle and Fade"
end tell
The word of is used to unambiguously refer to a particular object—here track number 13—of a user playlist named "Sparkle and Fade". This is a reference to the object to which it is a path. Notice the path in the next example.
Objects can have various properties—for instance, in iTunes "name" is a property of the object "track". You can access the value of a property with the AppleScript command get; and you can assign a new value to a property with set.
tell application "iTunes"
copy (get name of track 12 of user playlist "Favorites") to trackName
end tell
-- or
tell application "iTunes"
set name of track 4 of user playlist "Favorites" to "Everlong"
end tell
You can determine how the script will behave next by testing whether certain conditions are met. You can do this with an "if...then" statement; if a condition is true then do something:
tell application "iTunes"
if player state is paused then play
end tell
-- or
tell application "iTunes"
if (count of tracks of user playlist "Black Sea") is equal to 0 then delete user playlist "Black Sea"
end tell
On the next page is a table displaying commonly used iTunes objects and their properties, and example scripting syntax.