0

我正在编写一个简单的applescript,它应该关注一个应用程序并单击“cmd+1”。

这是我写的:

tell application "System Events"
    tell application process "appname"
        --Lobby focus
        activate
        keystroke "1" using command down
    end tell
end tell

但不是正常工作,而是发出一声哔哔声,应用程序甚至没有集中注意力。

我该如何解决这个问题?

4

1 回答 1

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
于 2012-10-22T11:39:50.397 回答