Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

King Boo

macrumors newbie
Original poster
Feb 3, 2011
3
0
I need help with this script:

set x to display dialog "What song do you want to hear?" default answer "" buttons {"OK"} default button 1
tell application "iTunes"
activate
play track "x" of playlist "Library"
end tell

As you can see, I am trying to get itunes to play a song that I enter, however, to my dismay, I cannot figure out how to get itunes to play the variable I have entered in. Note that this script:

tell application "iTunes"
activate
play track "x" of playlist "Library"
end tell

works if you change "x" to a song of your choice, such as "Blue Monday". I however think this is against the point and don't want to open applescript just to play a song. Please help with the user input and variable, because this is the problem I have been stumped on for a while. Thank you in advance. If you don't understand, I'm happy to clear up any misunderstandings.

I am also new here. I don't plan on coming to this site much to post, only to browse. Only rare circumstances like these require a post.
 
Okay the problem is you set the variable to the display dialog itself.

set x to text returned of (display dialog "What song do you want to hear?" default answer "" buttons {"OK"} default button 1)
tell application "iTunes"
activate
play track "x" of playlist "Library"
end tell
 
Last edited:
Yes, I know

That didn't fix it. Have you tried the script? That isn't the problem. I just need to know how to get this:

play track "x" of playlist "Library"

to find the song I typed in. Variable x is used to store that song. I can't get x to be a variable there. In fact, it just opens up itunes and tells me that it can't make some data into the expected type. This happens with your new script and mine.
 
Just take the speech marks of x and it'll work as in....

set x to text returned of (display dialog "What song do you want to hear?" default answer "" buttons {"OK"} default button 1)
tell application "iTunes"
activate
play track x of playlist "Library"
end tell
 
Yeah, thanks

I tried that before, but I hadn't done what Dalton 63841 told me to do along with it, since it had failed before. Thanks both of you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.