Applescript 结果到 txt 文件
Applescript results to txt file
我正在尝试编写一个 apple 脚本来获取未观看的电视节目并将文件名(最好没有完整路径,只是 "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"。我可以使用我目前评论过的 "Display dialog trackNames as text" 行并且它有效很好。我错过了什么?
节目列表包含引号和空格。只需使用 quoted form of
:
转义整个列表
do shell script "echo " & quoted form of unwatchedTVShows & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"
我正在尝试编写一个 apple 脚本来获取未观看的电视节目并将文件名(最好没有完整路径,只是 "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"。我可以使用我目前评论过的 "Display dialog trackNames as text" 行并且它有效很好。我错过了什么?
节目列表包含引号和空格。只需使用 quoted form of
:
do shell script "echo " & quoted form of unwatchedTVShows & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"