螢幕快照 2011-01-29 下午5.40.47.png
筆者之前寫過"[Tips]建立mac上常用的系統偏好設定捷徑"
目的是將常用的設定,建立捷徑到dock,以最少步驟呼叫出來修改

現在有個更快的方式,包括核取方塊這些動作通通包成AppleScript後
單鍵就可以開啟或關閉您要的功能

以我常用的開啟或關閉"網路共享"這功能為例
1.
打開AppleScript Editor,並輸入如下程式碼
----------------------------------------------

tell application "System Preferences"

activate

end tell

 

tell application "System Events"

tell process "System Preferences"

click menu item "共享" of menu "顯示方式" of menu bar 1

delay 2

tell window "共享"

click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1

delay 1

if (exists sheet 1) then

if (exists button "Turn AirPort On" of sheet 1) then

click button "Turn AirPort On" of sheet 1

delay 1

end if

click button "啟動" of sheet 1

end if

end tell

end tell

end tell


tell application "System Preferences"

quit

end tell

-------------------------------------
上面程式碼其實就是把您滑鼠點選動作,變成script批次執行
注意上面紅色的地方
若您的OS是英文版,記得將紅色地方改成對應的英文 
共享<-->Sharing
顯示方式<-->View
啟動<-->Start

2.
上面程式碼紅色row 11
這裡是對應系統偏好設定-->共享當中的項目,如下圖
我啟用的是internet共享,所以由上往下數是第11項
您可以根據自己要啟動或關閉的項目,改掉數字
螢幕快照 2011-01-29 下午5.25.03.png 

3.
完成之後,請儲存成"應用程式",存到您要的位置
螢幕快照 2011-01-29 下午5.10.26.png  

4.
最後,可以更改您剛剛寫的應用程式icon(不改也沒關係)
並將icon拉到dock做成捷徑
螢幕快照 2011-01-29 下午5.51.27.png  

最後,單鍵點選這個icon,就可以立即啟動或關閉網路共享了

----------------------------jimgau's comment

共享設定裡面共有12項
可以針對常用的幾項,各別存成幾個應用程式
對程式碼有興趣的,我做底下註解

----------------------------------------------

tell application "System Preferences" --啟動系統偏好設定

activate

end tell

 

tell application "System Events"

tell process "System Preferences"

click menu item "共享of menu "顯示方式of menu bar 1 --點選上方工作列當中的共享這一項目

delay 2

tell window "共享" --呼叫共享app

click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1 --點選第11項目的核取方塊

delay 1

if (exists sheet 1) then --點選網路共享的子設定,啟用airport分享功能

if (exists button "Turn AirPort On" of sheet 1) then

click button "Turn AirPort On" of sheet 1

delay 1

end if

click button "啟動of sheet 1 --點選核取方塊後,出現啟動或取消的對話視窗,選擇啟動

end if

end tell

end tell

end tell


tell application "System Preferences" --關閉系統偏好設定

quit

end tell

-----------------

資料參考來源 macworld

arrow
arrow
    全站熱搜

    jimgau 發表在 痞客邦 留言(1) 人氣()