使用AppleScript中的变量播放音乐(歌曲专辑或艺术家)

时间:2013-03-30 13:54:46

标签: variables applescript itunes

我正在尝试制作一个理解文字命令的“苹果剧本”“播放歌曲我们会摇滚你”或“播放艺术家女王”或“播放专辑”歌剧之夜“

使用songName artistName和albumName作为变量,但我不知道如何设置它们,因为它们取决于“播放歌曲名称”的答案中的前词(歌曲,艺术家,专辑)(播放必须是在该领域)。

我知道如何让它们播放我只需要设置这些变量以便只使用一个文本字段。

谢谢你的帮助(希望我很清楚)

3 个答案:

答案 0 :(得分:2)

尝试:

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

答案 1 :(得分:0)

你可以使用这样的东西来获取输入:

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

希望它有所帮助。

答案 2 :(得分:0)

Heres类似的东西,播放一个mp3文件

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