AppleScript 的听写设置
Dictation settings with AppleScript
我正在尝试创建一个 AppleScript 来打开或关闭听写(不仅仅是让它开始收听)。我的目标是在使用电池供电时能够禁用听写。我是 AppleScript 的新手,不知道该怎么做。我需要这个才能在 macOS Sierra 上工作。
我找到答案了!
如果有人需要,这是我的代码:
set quitting to 0
delay 1
repeat until quitting is 1
set PowerSource to (do shell script "pmset -g ps")
repeat until PowerSource does not contain "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "Off" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now off."
--END
repeat until PowerSource contains "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "On" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now on."
--END
end repeat
on quit
set quitting to 1
continue quit
end quit
只需在脚本编辑器中打开它并编译成应用程序即可。然后启动应用程序。希望这对您有所帮助!
我正在尝试创建一个 AppleScript 来打开或关闭听写(不仅仅是让它开始收听)。我的目标是在使用电池供电时能够禁用听写。我是 AppleScript 的新手,不知道该怎么做。我需要这个才能在 macOS Sierra 上工作。
我找到答案了!
如果有人需要,这是我的代码:
set quitting to 0
delay 1
repeat until quitting is 1
set PowerSource to (do shell script "pmset -g ps")
repeat until PowerSource does not contain "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "Off" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now off."
--END
repeat until PowerSource contains "AC Power" or quitting is 1
set PowerSource to (do shell script "pmset -g ps")
end repeat
--START
tell application "System Events"
set ProcessList to name of every process
if "System Prefrences" is in ProcessList then
set ThePID to unix id of process "System Prefrences"
do shell script "kill -KILL " & ThePID
end if
end tell
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
--Part 1:
tell process "System Preferences"
--Part 2:
delay 1
--Part 3:
tell application "System Events" to tell radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
tell application "System Events" to tell radio button "On" of radio group 1 of tab group 1 of window "Keyboard" of application process "System Preferences" of application "System Events" to if exists then click
end tell
end tell
tell application "System Preferences" to quit
display notification "Hey siri is now on."
--END
end repeat
on quit
set quitting to 1
continue quit
end quit
只需在脚本编辑器中打开它并编译成应用程序即可。然后启动应用程序。希望这对您有所帮助!