Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 28, 2011, 11:54 AM   #1
alternativemax
macrumors newbie
 
Join Date: Jan 2011
Play Specific Song in iTunes Applescript

I have created a simple applescript to play a specific song in iTunes, play a random song, or play a playlist named "Sleep". I am having an issue with the random song function, where "play (next song)" is not playing the next song. Also, is there a better way to throw the error message at the bottom? If the text entered is part of the name of a song, then the song will play but then the error will come up anyway because there isnt a song that is named exactly what was typed in. Also, is there a way to create a choosable list of "results" so if there is more than one result you could choose the song you want? Sorry for asking so many questions, but I'm lost. Thanks everyone! Here's the code:


repeat
tell current application
set song to the text returned of (display dialog "What song would you like to play? Or random?" default answer "")
end tell

tell application "iTunes"
if song is "Random" or song is "random" then
try
set all_music to user playlist "Music"
set shuffle of user playlist "Music" to false
set shuffle of user playlist "Music" to true
if current playlist is not "Music" then
play user playlist "Music"
else --FIX THIS
play (next track)
end if
set shuffle of user playlist "Music" to false
set shuffle of user playlist "Music" to true
end try
end if
if song is "sleep" or song is "Sleep" then
try
set the_playlist to user playlist "Sleep"
set shuffle of the_playlist to true
if current playlist is not the_playlist then
play the_playlist
else
play (next track)
end if
end try
end if
if song is not "Random" and song is not "random" and song is not "sleep" and song is not "Sleep" then
try
play track song
on error errMsg number errorNumber
try
set results to (every file track of playlist "Library" whose name contains song)
repeat with t in results
play t
end repeat
end try
end try
if file track song in playlist "Library" exists then
try
end try
else
tell current application
display dialog "Cannot locate song."
end tell
end if
end if
end tell
end repeat
alternativemax is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iTunes Radio... Never Play This Song thenk83 iOS 7 0 Jun 14, 2013 04:31 PM
Any way to get itunes to play every song in shuffle mode? mattg3 Mac Applications and Mac App Store 5 May 8, 2013 08:40 PM
iTunes Match song WON'T play in iOS 6 distemp iCloud and Apple Services 4 Oct 30, 2012 09:49 PM
How to play a specific song in Voice Control? AbhiKap55 iPod touch 6 Oct 13, 2012 07:50 PM
How to play a specific song in Voice Control? AbhiKap55 iPod touch 0 Oct 13, 2012 04:43 PM

Forum Jump

All times are GMT -5. The time now is 01:37 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC