我在Applescript上开始,另一个停止听写。我试图将它们一起运行,它只启动听写,但不会阻止它。我尝试了密钥代码方式,但此脚本将与VoiceOver一起使用,并且该方法不起作用。有没有办法让这个脚本检查启动/停止是否准备好并采取相应的行动?
tell application "System Events"
tell (get first process whose frontmost is true)
tell menu bar 1
tell menu bar item "Edit"
tell menu 1
click menu item "Start Dictation"
end tell
end tell
end tell
end tell
end tell
tell application "System Events"
tell (get first process whose frontmost is true)
tell menu bar 1
tell menu bar item "Edit"
tell menu 1
click menu item "Stop Dictation"
end tell
end tell
end tell
end tell
end tell
答案 0 :(得分:0)
您可以使用exists
命令
tell application "System Events"
tell (get first process whose frontmost is true)
tell menu 1 of menu bar item "Edit" of menu bar 1
if exists of menu item "Start Dictation" then
click menu item "Start Dictation"
else if exists of menu item "Stop Dictation" then
click menu item "Stop Dictation"
end if
end tell
end tell
end tell
-
或者您可以在菜单名称中使用单词,如下所示:
tell application "System Events"
tell (get first process whose frontmost is true)
tell menu 1 of menu bar item "Edit" of menu bar 1
click (first menu item whose name contains " Dictation") -- start or stop
end tell
end tell
end tell