0

I'm trying to write an apple script that gets the unwatched TVShows and puts the filename (preferably without the full path, just "whatever.m4v") in a text file.

Here is the code I have:

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

I get the following error:

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

If I replace the "unwatchedTVShows" varible in the do shell statement like this:

do shell script "echo " & "test" & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"

it works as I expect (I have a filename called "unwatchedTVShows.txt" and it contains the word "test". I can use the "Display dialog trackNames as text" line that I currently have commented and it works fine. What am I missing?

4

1 回答 1

0

节目列表包含引号和空格。只需使用以下命令转义整个列表quoted form of

do shell script "echo " & quoted form of unwatchedTVShows & " > /Volumes/Data/Media/Kodi/unwatchedTVShows.txt"
于 2017-11-13T05:41:06.087 回答