尝试引用字符串的最后一段时出现 Applescript 错误 -1728
我的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果我需要“of fileLoc”才能使其工作。
Turns out I needed "of fileLoc" in there to make it work.