1

我正在尝试制作一个告诉 iTunes 播放某个曲目的 AppleScript。这是我的代码。我很困惑,因为当我将“theCommand”设置为“播放 Shake Up Christmas by Artist Train”时,当我右键单击一封测试电子邮件并单击“应用规则”时,该脚本会起作用。但是,当我告诉它播放电子邮件告诉它播放的内容时,它不起作用。

using terms from application "Mail"
on perform mail action with messages messageList for rule aRule
    tell application "Mail"
        repeat with thisMessage in messageList
            try
                set theCommand to content of thisMessage as string
            on error errMsg
                display alert errMsg
            end try
        end repeat
    end tell
    tell application "iTunes"
        if theCommand contains "play" then
            if theCommand is equal to "play" then
                play
            else
                set prevTIDs to text item delimiters of AppleScript
                set text item delimiters of AppleScript to "play "
                set subject to text items of theCommand
                set text item delimiters of AppleScript to ""
                set subject to "" & subject
                set AppleScript's text item delimiters to " by artist "
                set delimitedList to every text item of subject
                set theTrack to the first item of delimitedList
                try
                    set theArtist to the second item of delimitedList
                    set artistIsDefined to true
                on error
                    set artistIsDefined to false
                end try
                set AppleScript's text item delimiters to prevTIDs
                if artistIsDefined is true then
                    try
                        play (every track in playlist 1 whose artist is theArtist and name is theTrack)
                        say "Playing " & theTrack
                    on error errMsg
                        say errMsg
                    end try
                else
                    play (every track in playlist 1 whose name is theTrack)
                end if
            end if
        else if theCommand is equal to "pause" then
            pause {}
        else if theCommand is equal to "stop" then
            stop {}
        end if
    end tell
end perform mail action with messages
end using terms from

Mac 将通过说“正在播放(曲目)”来回复电子邮件,但它不会播放曲目。该文件位于 Time Capsule 上的事实并不重要,因为 iTunes 可以访问它。(如果不能,iTunes 会在曲目名称左侧显示一个感叹号。)

4

1 回答 1

2

我的猜测是,您需要在此命令中将“every”一词更改为“first”...

play (every track in playlist 1 whose artist is theArtist and name is theTrack)

我没有测试我的理论,但我认为通过使用“每个”这个词,您可以从该命令中获得曲目列表(即使列表中只有 1 首曲目)。iTunes 不知道如何播放列表。iTunes 可以播放曲目。因此,通过使用“first”,您将找到找到的第一首曲目,因此它应该可以工作。或者,您可以获取列表的第一项...播放((每首曲目...)的第 1 项)。

于 2012-11-29T02:49:17.593 回答