我正在尝试编写一个苹果脚本,它可以获取未经监视的TVShows并将文件名(最好没有完整路径,只需“whatever.m4v”)放入文本文件中。
这是我的代码:
tell application "iTunes"
set watchedEpisodes to tracks of playlist "TV Shows" whose unplayed is false and played count > 0
set unwatchedEpisodes to tracks of playlist "TV Shows" whose unplayed is true
if (count unwatchedEpisodes) > 0 then
set trackNames to {}
repeat with anEpisode in unwatchedEpisodes
set end of trackNames to ((name of anEpisode) as text) & " of show " & show of anEpisode & " Filename: " & location of anEpisode
end repeat
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set unwatchedTVShows to trackNames as text
do shell script "echo " & unwatchedTVShows & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"
#display dialog trackNames as text
set AppleScript's text item delimiters to TID
end if
end tell
我收到以下错误:
error "iTunes got an error: sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file" number 2
如果我在do shell语句中替换“unwatchedTVShows”变量,如下所示:
do shell script "echo " & "test" & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"
它按预期工作(我有一个名为“unwatchedTVShows.txt”的文件名,它包含单词“test”。我可以使用“显示对话框trackNames作为文本”这一行,我目前已评论过它并且工作正常。我错过了什么?
答案 0 :(得分:0)
节目列表包含引号和空格。只需使用quoted form of
转义整个列表:
do shell script "echo " & quoted form of unwatchedTVShows & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"