Trygve
Trygve

Reputation: 1387

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

This works fine and produces a result of 4 as expected.

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

This results in an error "Can't get "ter" in someText. Access not allowed.

Since "offset" is part of the OS text functions, what is happening here? Both apps are installed on the computer.

Upvotes: 0

Views: 155

Answers (1)

ThrowBackDewd
ThrowBackDewd

Reputation: 1757

You can avoid the problem by creating your own function. When calling your own function within another application tell block, make sure to add the keyword my before the call to the function. See the example below...

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

Upvotes: 1

Related Questions