我正在尝试制作一个告诉iTunes播放某个曲目的AppleScript。这是我的代码。我很困惑,因为当我将“theCommand”设置为“播放由艺术家列车摇动圣诞节”时,当我右键单击测试电子邮件并单击“应用规则”时,该脚本可以正常工作。但是,当我告诉它播放电子邮件告诉它播放的内容时,它不起作用。
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会在曲目名称的左侧显示一个感叹号。)
答案 0 :(得分:2)
我的猜测是你需要在这个命令中将“every”改为“first”......
play (every track in playlist 1 whose artist is theArtist and name is theTrack)
我没有测试我的理论,但我认为通过使用“every”这个词,你可以得到该命令中的一个音轨列表(即使列表中只有一个音轨)。 iTunes不知道如何播放列表。 iTunes可以播放曲目。因此,通过使用“first”,您将获得第一个找到的曲目,因此它应该可以工作。或者你可以得到列表中的第一项......播放(每个曲目的第1项......)。