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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
No songs in itunes rickf78 iMac 0 Nov 5, 2010 02:53 AM
Can you just play a song in iTunes without importing it? Tumbleweed666 Mac Applications and Mac App Store 8 Apr 13, 2009 05:31 PM
Listening to Artist/Album Specific Songs in iTunes superspiffy Mac Applications and Mac App Store 3 Sep 8, 2008 03:45 PM
play single song in iTunes/automatic folder creation xpipe Mac Applications and Mac App Store 4 Jul 9, 2008 10:04 PM
can I play VLC songs in itunes wnameth General Mac Discussion 4 Jan 30, 2005 02:23 PM


All times are GMT -5. The time now is 09:13 PM.

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

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