Applescript help

Discussion in 'Mac Programming' started by King Boo, Feb 3, 2011.

  1. King Boo macrumors newbie

    Joined:
    Feb 3, 2011
    #1
    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.
     
  2. Dalton63841, Feb 3, 2011
    Last edited: Feb 3, 2011

    Dalton63841 macrumors 65816

    Dalton63841

    Joined:
    Nov 27, 2010
    Location:
    SEMO, USA
    #2
    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
     
  3. King Boo thread starter macrumors newbie

    Joined:
    Feb 3, 2011
    #3
    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.
     
  4. andy 111r macrumors newbie

    andy 111r

    Joined:
    Nov 13, 2010
    Location:
    leeds
    #4
    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
     
  5. King Boo thread starter macrumors newbie

    Joined:
    Feb 3, 2011
    #5
    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.
     

Share This Page