[心得] 用 AppleScript UI操作變更快速鍵
這只是個無聊的小程式,用途是透過 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
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章