片段1A在AppleScript中,如何从其他AppleScript调用/重用子例程?
on removeText(searchText, sourceText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to searchText
set sourceText to text items of sourceText
set text item delimiters of AppleScript to ""
set sourceText to "" & sourceText
set text item delimiters of AppleScript to prevTIDs
return sourceText
end removeText
片段2A
on removeText(searchText, sourceText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to searchText
set sourceText to text items of sourceText
set text item delimiters of AppleScript to ""
set sourceText to "" & sourceText
set text item delimiters of AppleScript to prevTIDs
return sourceText
end removeText
set theSentence to "I love Windows and I will always love Windows."
set theSentence to removeText("Windows", theSentence)
我发现这个子程序(片段1A)在片段2A方便,希望通过调用它的名字重用。我搜索了howto。然后我保存的片段1A作为/Users/henry/Library/Script\ Libraries/text.scpt
和在片段2A我取代
片断1B
on removeText(searchText, sourceText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to searchText
set sourceText to text items of sourceText
set text item delimiters of AppleScript to ""
set sourceText to "" & sourceText
set text item delimiters of AppleScript to prevTIDs
return sourceText
end removeText
与
片断3
use script "text"
并得到片段2B然后我跑代码段2b,但我得到一个错误,说«script» doesn’t understand the “removeText” message.
参考:“使用说明”(指通过搜索use script "Happy Fun Ball"
在https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html中发现的部分)
于是我又回到谷歌,发现一个建议我应该片断1A另存为“脚本程序”。
底部。在一个人的例子,它是
片断4
tell application "NonStayOpen"
launch
stringTest("Some example text.")
end tell
所以我出口段1a中作为/Users/henry/Library/Script\ Libraries/text.app
和写片断2C
snippet 2c
tell application "text"
launch
set theSentence to "I love Windows and I will always love Windows."
set theSentence to removeText("Windows", theSentence)
end tell
然后我跑了,并得到一个错误{} doesn't match the parameters {searchText, sourceText} for removeText.
之后,我试图首先要追加removeText(searchText, sourceText)
到片断1A(获得片段1C),并远销它来代替/Users/henry/Library/Script\ Libraries/text.app
,但得到了一个错误运行时,失败;
其次要在片段1A removeText()
更换removeText(searchText, sourceText)
(获得片段1D),并远销它来代替/Users/henry/Library/Script\ Libraries/text.app
但在运行时得到一个错误,失败。
在代码片段2a中,如何从另一个AppleScript或“脚本应用程序”(请参见参考资料2)调用/重用子例程(代码段1a)?
这是一个详细的问题描述。请帮忙,非常感谢你!