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

时间:2016-09-18 02:55:07

标签: command applescript conditional dictation

我创建了一个要使用dictation命令激活的脚本"启用共享"成功打开系统首选项/共享/然后它将自动单击该复选框,无论它是已启用还是已禁用。

我想有两个听写命令,一个用于启用共享,另一个用于禁用共享。当我说"启用共享"时,如何添加条件?它将通过脚本运行,如果已经选择了共享复选框,只需退出系统首选项,而不是单击该复选框(如果已经选中),实际上会取消选中该复选框?

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

2 个答案:

答案 0 :(得分:0)

在这里,我为你修好了。

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

答案 1 :(得分:0)

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

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