使用AppleScript修改设置/系统偏好设置 [英] Using AppleScript to modify settings/system preferences

查看:640
本文介绍了使用AppleScript修改设置/系统偏好设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个AppleScript,以切换空格的自动重新排列.我可以通过AppleScript打开系统偏好设置并进入任务控制设置,但是我不确定如何选中要更改的复选框.

I am trying to make an AppleScript that toggles automatic rearranging of spaces. I am able to get the AppleScript to open system preferences and go into mission control settings, however i am not sure how to check the box which i want to change.

    tell application "System Preferences"
    activate
end tell

tell application "System Events"
    tell process "System Preferences"
        click menu item "Mission Control" of menu "View" of menu bar 1
    delay 2
    tell window "Mission Control"
            //additional code goes here
    end tell
    end tell
end tell

有没有办法查看窗口的组成部分,因此我能够访问切换设置的复选框之前知道是否需要进入表格或其他内容

Is there a way to see what the components of the window are so i know if i need to go into a table, or something else, before i am able to access the check boxes that toggle the settings

推荐答案

这应该符合您的要求.

在此示例中,Automatically rearrange Spaces based on most recent use是要检查的复选框.

In this example Automatically rearrange Spaces based on most recent use is the checkbox you want to check.

tell application "System Preferences"
    activate
    delay 2
    set the current pane to pane id "com.apple.preference.expose"
    delay 2
    tell application "System Events"
        click checkbox "Automatically rearrange Spaces based on most recent use" of group 2 of window "Mission Control" of application process "System Preferences"
    end tell
    quit
end tell

如果您只想在未选中的情况下进行检查,就可以这样做:

And this if you wanna check it only if it's not checked:

tell application "System Preferences"
    activate
    delay 2
    set the current pane to pane id "com.apple.preference.expose"
    delay 2
    tell application "System Events"
        tell checkbox "Automatically rearrange Spaces based on most recent use" of group 2 of window "Mission Control" of application process "System Preferences"
            if (get its value) = 0 then click it
        end tell
    end tell
    quit
end tell

如果要在窗口中列出所有UIElement:

And if you wanna list all the UIElements in the window:

set myArray to {}
tell application "System Preferences"
    activate
    delay 2
    set the current pane to pane id "com.apple.preference.expose"
    delay 2
    tell application "System Events"
        tell window "Mission Control" of application process "System Preferences"
            repeat with uiElem in entire contents as list
                set myArray to myArray & ((class of uiElem as string) & " : " & name of uiElem as string)
            end repeat
        end tell
    end tell
end tell

这篇关于使用AppleScript修改设置/系统偏好设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆