AppleScript "offset" Microsoft Outlook 失败
AppleScript "offset" failure with Microsoft Outlook
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
这会导致某些文本中出现错误 "Can't get "ter"。不允许访问。
由于 "offset" 是 OS 文本函数的一部分,这里发生了什么?这两个应用程序都安装在计算机上。
您可以通过创建自己的函数来避免该问题。在另一个应用程序的 tell 块中调用您自己的函数时,请确保在调用该函数之前添加关键字 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
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
这会导致某些文本中出现错误 "Can't get "ter"。不允许访问。
由于 "offset" 是 OS 文本函数的一部分,这里发生了什么?这两个应用程序都安装在计算机上。
您可以通过创建自己的函数来避免该问题。在另一个应用程序的 tell 块中调用您自己的函数时,请确保在调用该函数之前添加关键字 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