I’m trying to write an Applescript to toggle the hyperlinks in Microsoft word. (This is normally done by hitting Alt+F9).
Here’s my script, but it doesn’t work:
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
That just gives me an error:
“Expected end of line but found identifier”
If I use:
tell application "System Events"
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
end tell
it works but does nothing.
And if I use:
tell application "System Events"
tell application "Microsoft Word"
keystroke "Hello"
end tell
end tell
It just prints “Hello” in the applescript window. I need it to affect MS word.
No need to script simulated keyboard shortcuts here. To toggle field codes (e.g. between the form
{HYPERLINK "http://www.stackoverflow.com"}and actual hyperlinks), use this script:Note that this will also switch other field codes, such as page numbers, off and on.