尝试引用字符串-1728的最后一段时出现Applescript错误

时间:2011-08-25 23:18:15

标签: string applescript

我的代码:

tell application "iTunes"
    set ofi to fixed indexing
    set fixed indexing to true
    set sel to selection
    repeat with i from 1 to (count sel)
        tell (item i of my sel)
            set fileLoc to the location as Unicode text
            set fileLoc to my findAndReplace(":", "
", fileLoc)
            --display dialog return & fileLoc buttons {"Ok"} default button 1      with icon 0

            --Show Name
            set showName to paragraph -3 of fileLoc
            set show to (showName as text)

            --Season #
            set seasonNum to the last word of paragraph -2 of fileLoc
            try
                set season number to (seasonNum as number)
            end try

            --Episode #
                    --*****ERROR HAPPENS HERE*****
            set test to the first word of the last paragraph
            set episodeNum to (the word 2 of paragraph -1)
            --set episode number to episodeNum as number


            --Episode name
            set episodeName to characters 4 thru -5 of paragraph -1 of fileLoc
            set name to episodeName as text

            --Video Kind
            set video kind to TV show
        end tell
    end repeat
    set fixed indexing to ofi
 end tell

on findAndReplace(tofind, toreplace, TheString)
    set ditd to text item delimiters
    set res to missing value
    set text item delimiters to tofind
    repeat with tis in text items of TheString
        if res is missing value then
            set res to tis
        else
            set res to res & toreplace & tis
        end if
    end repeat
    set text item delimiters to ditd
    return res
end findAndReplace

我得到了:

error "iTunes got an error: Can’t get word 1 of last paragraph of file track id 7141 of user playlist id 5157 of source id 69." number -1728 from word 1 of last paragraph of file track id 7141 of user playlist id 5157 of source id 69

我试图解析的文字如下:

Users
christopher
TV Shows
How I Met Your Mother
Season 5
01 Definitions.m4v

1 个答案:

答案 0 :(得分:0)

原来我需要“of fileLoc”来使它工作。