AppleScript和加载代码库
纯粹作为一个实验,我试图用AppleScript做一些相当复杂的事情,主要是作为一个学术练习,而不是任何东西,但我遇到了麻烦。下面是正在发生的事情 首先,我有一个名为“ascr\u code\u library.scpt”的代码库,其中只包含一个方法:AppleScript和加载代码库,applescript,static-libraries,Applescript,Static Libraries,纯粹作为一个实验,我试图用AppleScript做一些相当复杂的事情,主要是作为一个学术练习,而不是任何东西,但我遇到了麻烦。下面是正在发生的事情 首先,我有一个名为“ascr\u code\u library.scpt”的代码库,其中只包含一个方法: on return_string_position(this_item, this_str, delim) set old_delims to AppleScript's text item delimiters set Appl
on return_string_position(this_item, this_str, delim)
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
set this_list to text items of this_str
set found_pos to 0
repeat with i from 1 to the count of this_list
if item i of this_list is equal to this_item then set found_pos to i
end repeat
set AppleScript's text item delimiters to old_delims
return found_pos
end return_string_position
然后,我有了这个脚本,“test-2.scpt”。它的功能非常简单,并且非常简单:
set scr_lib to load script (choose file with prompt "Please pick a library")
tell scr_lib
return_string_position("Who", "Who am I?", " ")
end tell
但当我运行脚本并选择文件时,得到的是以下错误:
*“«数据SCPT4D617259332E3000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*
那么我错在哪里呢?据我所知,它正在正确加载脚本。但在这样一个简单的脚本中,我还能出什么差错呢?我试着在方法调用前加上“my”,但也没用。有什么想法吗?如中所述,我更喜欢这个脚本,因为它避免了分隔符并返回每个实例
on return_string_position(this_item, this_str)
set theWords to every word of this_str
set matchedWords to {}
repeat with i from 1 to count of theWords
set aWord to item i of theWords
if item i of theWords = this_item then set end of matchedWords to i
end repeat
return matchedWords
end return_string_position
return_string_position("very", "The coffee was very very very very very ... very hot.")
您可以这样调用脚本:
run script file ((path to desktop as text) & "test 1.scpt") with parameters {"very", "The coffee was very very very very very ... very hot."}
你的代码对我来说很好,没有错误。一定还有什么事你没有告诉我们。。。因为你展示的代码是有效的。