2

I'm making trying to make an apple script that understands a text command "Play song We will Rock You" or "Play artist Queen" or "Play album A Night at the opera"

using songName artistName and albumName as variables, but i don't know how to set them, as they depend on the previuos word (song,artist,album) in an answer which is "Play song songName" (PLAY must be in the field).

I know how to make them play I just need to set those variables in order to use just one textfield.

Thanks for you help (hope I was clear)

4

3 回答 3

2

Try:

set xxx to text returned of (display dialog "Play song, Play artist, Play album " buttons {"Cancel", "OK"} default button "OK" default answer "Play song Here I Come")

set myChoices to {"Play song ", "Play artist ", "Play album "}

tell application "iTunes"
    repeat with i from 1 to count myChoices
        set aChoice to (item i of myChoices)
        if xxx starts with aChoice then
            set AppleScript's text item delimiters to aChoice
            set theRest to text items 2 thru -1 of xxx
            set AppleScript's text item delimiters to {""}
            set theRest to theRest as text

            if i = 1 then
                play (first track whose name = theRest)
            else if i = 2 then
                play (first track whose artist = theRest)
            else if i = 3 then
                play (first track whose album = theRest)
            end if
            exit repeat
        end if
    end repeat
end tell
于 2013-03-30T15:42:29.397 回答
0

You can use something like this to get input:

display dialog "Enter the album name:" default answer "CocoaRocks"
set the albumName to the text returned of the result

Hope it helps.

于 2013-03-30T14:20:42.320 回答
0

Heres something similar, plays a mp3 file

set audioFile to (POSIX path of (choose file of type "mp3")) do shell script "afplay " & audioFile

于 2015-07-10T05:04:47.240 回答