(* Itunes Applescript Version 4.2 *)
tell application "iTunes"
set trn1 to text returned of (display dialog " What song or playlist would you like to play?" default answer " Song or Playlist goes here")
try
(* this part of the script tells the appliaction to try a certain function. Such as telling the application to play a certain track or Playlist that was specified in the dialog above *)
play track trn1
(* At this part of the script it tells Itunes to play the specified track *)
on error
play playlist trn1
(* At this part of the script it tells Itunes to play the specified Playlist *)
end try
set ct to current track
(* At this Part You are setting the variable ct to the current track *)
get artist of current track
(* At this part we are getting the artist of the Current track*)
set artist1 to result
get name of ct
set currenttrack to result
display dialog currenttrack & " By:" & artist1 buttons {"Yes", "No"} default button 1
set response1 to (button returned of result)
if response1 is "no" then
stop track
display dialog "what song or playlist would you like to play?" default answer " Song or Playlist goes here"
set trn2 to text returned of result
try
play track trn2
on error
play playlist trn2
end try
set ct to current track
get artist of ct
set artist2 to result
get name of ct
set currenttrack2 to result
try
get playlist of ct
set playlist1 to result
end try
display dialog currenttrack2 & " By:" & artist2
end if
(* Displays dialog Saying the name of the current track that is play and who the track is by *)
end tell
(* Copyright Protected*)
Hi,
the script throws an error, if the entered string matches neither a track nor a playlist.
Rather than catching errors I’d check for the existence of the track/playlist
tell application "iTunes"
repeat
set trn1 to text returned of (display dialog " What song or playlist would you like to play?" default answer " Song or Playlist goes here")
if exists track trn1 then
play track trn1
else if exists playlist trn1 then
play playlist trn1
else
display dialog quote & trn1 & "\" matches neither a track nor a playlist" buttons {"Cancel", "Try Again"} default button 2
end if
end repeat
set ct to current track
(* At this Part You are setting the variable ct to the current track *)
.
Thank you.