如果复选框已被选中,则退出应用程序

If check box is already selected, then quit application

我创建了一个使用听写命令激活的脚本"Enable Sharing",它成功打开了系统偏好设置/共享/然后它会自动点击复选框是否已经启用。

我想要两个听写命令,一个用于启用共享,一个用于禁用共享。我如何添加一个条件,当我说 "Enable Sharing" 时,它会 运行 通过脚本,如果共享复选框已经被选中,只需退出系统偏好设置而不是单击该复选框,如果它实际上已经被选中会取消选中该复选框吗?

activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click button "Sharing" of scroll area 1 of window "System Preferences"
    end tell
end tell
activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click checkbox 1 of row 2 of table 1 of scroll area 1 of group 1 of window "Sharing"
    end tell
end tell
tell application "System Preferences"
quit
end tell

这里,我帮你解决了。

activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click button "Sharing" of scroll area 1 of window "System Preferences"
    end tell
end tell
activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"


        set theCheckbox to checkbox 1 of row 2 of table 1 of scroll area 1 of group 1 of window "Sharing"
        tell theCheckbox
            if false then click theCheckbox
        end tell


    end tell
end tell
tell application "System Preferences"
    quit
end tell

尤里卡!!!在尝试了各种不同的组合之后..这是我实际需要的脚本..

activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        click button "Sharing" of scroll area 1 of window "System Preferences"
    end tell
end tell
activate application "System Preferences"
delay 1
tell application "System Events"
    tell process "System Preferences"
        tell checkbox 1 of row 2 of table 1 of scroll area 1 of group 1 of window "Sharing" to if value is 0 then click
        delay 1
    end tell
end tell
tell application "System Preferences"
     quit
end tell