我正在尝试制作一个告诉 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 会在曲目名称左侧显示一个感叹号。)