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

发布于 2024-12-01 14:58:24 字数 2121 浏览 0 评论 0原文

我的代码:

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

My code:

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

and I get:

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

The text I'm trying to parse looks like:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2024-12-08 14:58:24

结果我需要“of fileLoc”才能使其工作。

Turns out I needed "of fileLoc" in there to make it work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文