我创建了一个脚本,通过使用听写命令"启用共享"来激活它,它会成功打开系统偏好/共享/然后它会自动点击复选框,无论它已经启用或禁用。
我想有两个听写命令,一个用于启用共享,一个用于禁用共享。我如何添加一个条件,当我说"启用共享"时,它会运行整个脚本,如果共享复选框已经被选中,只要退出系统偏好,而不是点击那个复选框,如果它已经被选中,实际上会取消选中那个复选框?
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