作者hpo14 (雨)
看板MacDev
标题[心得] 用 AppleScript UI操作变更快速键
时间Mon Apr 22 19:14:19 2013
这只是个无聊的小程式,用途是透过 AppleScript 模拟使用者 UI 操作
关闭 Spotlight 快速键并开启切换输入法的快速键
1. 开 AppleScript Editor 贴虚线内容贴上,按下执行即可使用。
2. 或在 Editor 另存为程式套件,之後即可使用。
只提供程式码
(参考多份网路资料请引用部份程式码,且有使用 UI ElementInspector 作为辅助)
ps. 上色的部份表示他们是同一行
----------------------------------->8----------------------------------------
GUIScripting_status() -- 引用部份
tell application "System Preferences"
activate
reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
end tell
tell application "System Events"
tell process "System Preferences"
tell window "Keyboard"
-- 个人写作部份开始
repeat with lrow in row of table 1 of scroll area 1 of
splitter group 1 of tab group 1
set lrow_text to (value of static text 1 of lrow)
if lrow_text = "Spotlight" then
select lrow
repeat with rrow in (row of outline 1 of scroll area 2
of splitter group 1 of tab group 1)
select rrow
if (value of checkbox 1 of UI element 1 of rrow) as boolean
is true then
click checkbox of UI element 1 of rrow
end if
end repeat
end if
if lrow_text contains "Keyboard" or "键盘" then
select lrow
repeat with rrow in (row of outline 1 of scroll area 2 of splitter
group 1 of tab group 1)
if ((value of static text 1 of UI element 2 of rrow) as string)
contains "input" or "输入" then
select rrow
if (value of checkbox 1 of UI element 1 of rrow) as boolean
is false then
click checkbox of UI element 1 of rrow
end if
end if
end repeat
end if
end repeat
-- 个人写作部份结束
end tell
end tell
end tell
tell application "System Preferences" to quit
-- 引用部份开始
on GUIScripting_status()
-- check to see if assistive devices is enabled
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
set result to display dialog "This script utilizes the built-in Graphic
User Interface Scripting architecture of Mac OS x which is
currently disabled." & return & return & "Please click 'OK' to
provide your password to activate GUI Scripting" with icon 1 buttons
{"OK", "Enable without password"} default button 1
if button returned of result = "Enable without password" then
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.universalaccess"
display dialog "Activate GUI Scripting by selecting the checkbox
\"Enable access for assistive devices\" in the Universal Access
preference pane." with icon 1 buttons {"OK"} default button 1
delay 3
end tell
else
enabledGUIScripting(true)
end if
end if
end GUIScripting_status
on
enabledGUIScripting(switch)
tell application "System Events"
activate
set UI elements enabled to switch
return UI elements enabled
end tell
end enabledGUIScripting
-- 引用部份结束
----------------------------------->8----------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.204.46.87