【问题标题】:Play music (song album or artist) with variables in AppleScript在 AppleScript 中使用变量播放音乐(歌曲专辑或艺术家)
【发布时间】:2013-03-21 02:27:33
【问题描述】:

我正在尝试制作一个可以理解文本命令的苹果脚本“播放歌曲我们将摇滚你”或“播放艺术家皇后”或“播放专辑 A Night at the Opera”

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

我知道如何让它们发挥作用,我只需要设置这些变量就可以只使用一个文本字段。

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

【问题讨论】:

  • 始终包含您自己的代码。我们希望看到一些代码,以便我们知道您已尝试解决问题。

标签: variables applescript itunes


【解决方案1】:

试试:

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

【讨论】:

    【解决方案2】:

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

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

    希望对你有帮助。

    【讨论】:

    • 我需要使用一个文本来控制“播放歌曲歌曲名称”“播放艺术家艺术家名称”“播放专辑专辑名称”。这就是为什么我有麻烦
    • 因此您需要解析“播放歌曲我的心在歌唱”或“播放专辑 Singing Hearts”之类的字符串,以便您可以隔离歌曲或专辑标题以发送到 iTunes。是这样吗? (顺便说一句:这里有很好的资源:@​​987654321@)
    【解决方案3】:

    类似的,播放mp3文件

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-04
      相关资源
      最近更新 更多