2016-03-20 75 views
0
tell application "Microsoft Entourage" 
    set someText to "tester" 
    set result to offset of "ter" in someText 
    result 
end tell 

這工作正常,併產生預期的結果4。與Microsoft Outlook的AppleScript「偏移」失敗

tell application "Microsoft Outlook" 
    set someText to "tester" 
    set result to offset of "ter" in someText 
    result 
end tell 

這將導致一個錯誤‘在someText。不允許訪問。

既然‘「無法獲取’之三失調’是的OS文本功能的一部分,這裏發生了什麼?這兩個應用程序安裝在計算機上

回答

1

您可以通過創建自己的函數來避免此問題。在另一個應用程序中調用您自己的函數時,請確保在調用該函數之前添加關鍵字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 
相關問題