tell application "Microsoft Entourage"
set someText to "tester"
set result to offset of "ter" in someText
result
end tell
这样可以正常工作,并按预期产生4的结果。
tell application "Microsoft Outlook"
set someText to "tester"
set result to offset of "ter" in someText
result
end tell
这导致错误"无法获得" ter"在someText中。不允许访问。
因为"偏移"是OS文本函数的一部分,这里发生了什么?这两个应用程序都安装在计算机上。
答案 0 :(得分:1)
您可以通过创建自己的功能来避免此问题。在另一个应用程序tell block中调用自己的函数时,请确保在调用函数之前添加关键字my
。请参阅下面的示例...
on run
tell application "Microsoft Outlook"
set someText to "tester"
set searchString to "ter"
set rslt to my textOffset(searchString, someText)
end tell
end run
on textOffset(subString, theString)
return offset of subString in theString
end textOffset