我正在编写一个简单的应用程序,应该关注应用程序,然后单击“cmd + 1”。
这就是我写的:
tell application "System Events"
tell application process "appname"
--Lobby focus
activate
keystroke "1" using command down
end tell
end tell
但是没有工作,有一声嘟嘟声,应用程序甚至没有关注。
我该如何解决这个问题?
答案 0 :(得分:1)
您无法告诉要激活的进程。将其更改为set frontmost to true
:
tell application "System Events"
set frontmost of process "Finder" to true
keystroke "1" using command down
end tell
或告诉应用程序激活:
activate application "Finder"
tell application "System Events"
keystroke "1" using command down
end tell
如果应用程序没有打开窗口,reopen
将打开一个新的默认窗口:
tell application "Finder"
reopen
activate
end tell
tell application "System Events"
keystroke "1" using command down
end tell