为什么我的AppleScript程序说iTunes正在播放一首曲目,而iTunes不是';你真的不这样做吗?

为什么我的AppleScript程序说iTunes正在播放一首曲目,而iTunes不是';你真的不这样做吗?,applescript,Applescript,我正在尝试制作一个苹果脚本,告诉iTunes播放某个曲目。这是我的密码。我很困惑,因为当我将“命令”设置为“播放艺术家训练带来的圣诞震撼”时,当我右键单击测试电子邮件并单击“应用规则”时,脚本就起作用了。但是,当我告诉它播放电子邮件告诉它播放的内容时,脚本就不起作用了 using terms from application "Mail" on perform mail action with messages messageList for rule aRule tell applic

我正在尝试制作一个苹果脚本,告诉iTunes播放某个曲目。这是我的密码。我很困惑,因为当我将“命令”设置为“播放艺术家训练带来的圣诞震撼”时,当我右键单击测试电子邮件并单击“应用规则”时,脚本就起作用了。但是,当我告诉它播放电子邮件告诉它播放的内容时,脚本就不起作用了

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会回复电子邮件说“播放(曲目)”,但不会播放曲目。文件在时间胶囊上这一事实并不重要,因为iTunes可以访问它。(iTunes可能会在曲目名称的左边显示一个感叹号,如果它不能的话。)

我猜你需要在这个命令中将单词“every”改为“first”

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

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

从4年前开始,已经有了一个公认的答案。它不能解决你的问题吗?如果没有,请告诉我们遗漏了什么。@mklement0我希望人们对我的问题投赞成票或反对票,这不是奖金的目的。奖金不是为了增加人气(只有谷歌抽奖的运气,也许像你的个人博客这样的东西能帮上忙),而是为了找到尚未解决的问题的解决方案。旁白:在你的场景中,你会把你的赏金奖励给谁?@mklement0在Meta网站上,我问如何在一个问题上获得投票,Alexei Levenkov建议我“赏金是要求更多人关注这个问题的官方方式。”[sic]。我不能代表Alexei说话,但我的阅读(以及总体理解力)其中一个原因是,如果你还没有找到解决方案,你可能会要求更多的人关注你的问题,而不是要求更多的人关注你的问题。同样,鉴于SO的流行,如果人们有相同的问题,谷歌会引导他们到你的帖子。在这里,你能做的最好的事情就是尽可能地帮助你的问题,提供一个描述性的(a)标题,(b)正文和(c)标签。