1

我创建了一个脚本,通过使用成功打开系统偏好设置/共享/的听写命令“启用共享”来激活它,然后它将自动单击复选框,无论它是否已启用或禁用。

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

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
4

2 回答 2

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
于 2016-09-18T09:41:26.357 回答
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
于 2016-09-19T20:30:27.927 回答