0

我正在尝试使用以下脚本导航到系统首选项中的安全窗格,如果窗格已打开并最小化,则脚本无法将其置于前面。有没有办法连同激活,我可以把它带到前面

tell application "System Preferences"
     activate
     set current pane to pane "com.apple.preference.security"
end tell
4

2 回答 2

1

此脚本检查窗口的状态。

  • 如果窗口不存在打开它。
  • 如果窗口存在但已小型化,则使其可见。
  • 如果窗口可见,则什么也不做。

    tell application "System Preferences"
        activate
        if exists window "Security & Privacy" then
            tell window "Security & Privacy" to if it is miniaturized then set miniaturized to false
        else
            set current pane to pane "com.apple.preference.security"
        end if
    end tell
    
于 2018-10-30T11:22:23.893 回答
0

我会简单地退出系统偏好设置然后再次激活它:

tell application "System Preferences"
    quit
    activate
    set current pane to pane "com.apple.preference.security"
end tell

注意:有时,退出然后立即激活应用程序可能会因为两个进程重叠而失败,从而产生错误。如果发生这种情况,以下额外的几行(在原始答案的上下文中添加)应该可以缓解这种情况:

tell application "System Preferences"
    quit

    repeat while it is running
        delay 0.2
    end repeat

    activate
    set current pane to pane "com.apple.preference.security"
end tell
于 2018-10-30T13:50:43.693 回答