将 OS X 应用程序置于最前面,即使它是不同的 Mission Control space

Bringing an OS X application to the front even if it's a different Mission Control space

我想做的是可靠地切换到应用程序,即使它在不同的 space 中打开,使用 shell 脚本。例如,假设我在 space 1,并且有一个 Safari window 在 space 2 打开但不在 space 1。我希望能够切换到适当的 space 以使 Safari 处于活动状态。目前我正在使用 AppleScript:

osascript -e "
tell application \"Safari\"
    activate
end tell
"

但这只会使菜单栏切换到 Safari,而不是移动到包含 Safari window 的 space。

检查您的系统偏好设置 -> 任务控制

你勾选了第二个复选框吗? (When switching to ....) 如果是 - 你的 applescript 将工作。

此外,您可以将其更改为:

#!/usr/bin/osascript
tell application "Safari"
    activate
end tell

例如只需将 osascript 添加为 shebang 并使脚本可执行:

chmod 755 ~/path/to/the/above/script_file