我正在尝试编写一个Applescript来切换Microsoft Word中的超链接。 (这通常是通过按Alt + F9完成的。)
这是我的脚本,但它不起作用:
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
这只是给了我一个错误:
“预期结束但找到标识符”
如果我使用:
tell application "System Events"
tell application "Microsoft Word"
keystroke F9 using {option down}
end tell
end tell
它有效,但什么也没做。
如果我使用:
tell application "System Events"
tell application "Microsoft Word"
keystroke "Hello"
end tell
end tell
它只是在applescript窗口中打印“Hello”。我需要它来影响MS字。
答案 0 :(得分:1)
此处无需编写模拟键盘快捷键的脚本。要切换字段代码(例如,在表单{HYPERLINK "http://www.stackoverflow.com"}
和实际超链接之间),请使用以下脚本:
# toggle field codes
# same as option + F9
# tested in Microsoft® Word 2008 for Mac v 12.2.3
tell application "Microsoft Word"
set theView to active window's active pane's view
if (show field codes of theView) then
set show field codes of theView to false
else
set show field codes of theView to true
end if
end tell
请注意,这也会关闭和打开其他字段代码,例如页码。