Hi. I’m brand new to AppleScript and have FINALLY been able to write some simple, unsophisticated scripts that actually work. I’m sure they are very inefficient and poorly done, but they’re a start.
I need help with a simple iTunes script, which I will include here. I want to be able to play samples (or entire songs) in my iTunes Library by Artist Name, Rating, and then give the user a choice whether to hear a shot sample or the entire song.
I can get the 10 second sample to play, but not the entire song. The sample has a “delay 10” statement, but the entire song has no delay statement at all. I can’t figure out what is wrong.
Can anybody help me mend my ways? Also, I’d love to know a more efficient way to get user input on a single Display Dialog, instead of doing it 3 times. Any help appreciated. BTW, I’m on 10.6.8. Script below.
Thanks, Lou Dina
(*
This script plays songs in iTunes, based on user input. It asks the user for the name of the artist they wish to hear and the minimum rating, then cycles through each song. Currently, it is set to play only a short sample instead of the entire song, like when scanning a radio station. This script does not alter the iTunes database, create playlists, etc.
written by Lou Dina - 6/30/2012 (my first AppleScript)
*)
tell application “iTunes”
activate
--get User input on the artist they would like to hear in iTunes
display dialog "Enter the name (or part of the name) of an artist to hear a short sample of each artist track in the music library rated 3-stars or above. Click Cancel to Abort.
" default answer "" buttons {"Cancel", "Continue"} default button "Continue"
set user_Artist to the text returned of the result
--get User input on the rating for the above list
display dialog "Enter the \"minimum\" rating (1, 2, 3, 4, or 5) of the songs you would like to hear. Click Cancel to Abort.
" default answer "" buttons {"Cancel", "Continue"} default button "Continue"
set user_Rating to the text returned of the result
--get User input on whether they want to whole song played, or just a snippet
display dialog "Please choose to hear the Whole Song, a 10 second sample, or click Cancel to abort. " buttons {"Cancel", "Entire Song", "10-Second Sample"} default button "Entire Song"
set song_Length to the button returned of the result
--create song list for the chosen artist by unique track id instead of by name to make sure songs of the same name by other artists are not played
set song_list to id of every track of playlist 1 whose artist contains user_Artist and rating is greater than or equal to (user_Rating * 20)
--cycle through songs and play. Stop when end of list is reached.
repeat with i in song_list
-- set track_to_play to contents of song_list
if song_Length is equal to "10-Second Sample" then
play track id i
delay 10
else if song_Length is equal to "Entire Song" then
play track id i
--play track id i -- this doesn't work. It quickly lists songs but doesn't play unless I add a "delay". Hmmmmm.
--delay 10
end if
end repeat
stop
end tell
Model: Mac Pro
AppleScript: 2.3
Browser: Firefox 13.0.1
Operating System: Mac OS X (10.6)