2013-11-03 44 views
1

在OS X 10.8中,我有一個整潔的小AppleScript,我用它在不使用鼠標的情況下快速切換藍牙。AppleScript切換藍牙

我更新到10.9,它將幾個UI更改添加到系統首選項。除此之外,它取代了將藍牙從複選框切換到按鈕的元素。我的腳本現在被破壞,因此我的工作流程也是如此。

問題是,按鈕的名稱從「打開藍牙」變爲「關閉藍牙」,具體取決於其狀態。我對AppleScript沒有足夠的把握來找出解決方法,並且想知道你們是否可以幫助我。

回答

5

這10.9爲我工作:

tell application "System Preferences" 
    reveal pane "com.apple.preferences.Bluetooth" 
end tell 
tell application "System Events" to tell process "System Preferences" 
    click button 6 of window 1 
end tell 
quit application "System Preferences" 

你也使用blueutil

/usr/local/bin/blueutil|grep -q 'Power: 1';/usr/local/bin/blueutil power $? 
+0

這工作得很好。謝謝。 – user1892304

0

爲我工作,沒有藍UTIL:

告訴應用程序 「系統偏好設置」 顯示窗格ID「com.apple.preferences.Bluetooth」 - 激活

set the current pane to pane id "com.apple.preferences.Bluetooth" 

try 
    tell application "System Events" to tell process "System Preferences" 
     click button "Turn Bluetooth Off" of window "Bluetooth" 

     click button "Turn Bluetooth Off" of sheet 1 of window "Bluetooth" of application process "System Preferences" of application "System Events" 
    end tell 

    delay 1 

on error 
    tell application "System Events" to tell process "System Preferences" 
     click button "Turn Bluetooth On" of window "Bluetooth" 
     quit 
    end tell 

end try 

末告訴

0
tell application "System Preferences" 
    reveal pane "com.apple.preferences.Bluetooth" 
end tell 
tell application "System Events" to tell process "System Preferences" 
    repeat until exists window "Bluetooth" 
    end repeat 
    try 
     click button "Turn Bluetooth Off" of window "Bluetooth" 
     do shell script "networksetup -setairportpower airport off" 
    on error 
     click button "Turn Bluetooth On" of window "Bluetooth" 
     do shell script "networksetup -setairportpower airport on" 
    end try 
end tell 
tell application "System Preferences" to quit 
+1

包括wifi切換 - 在高塞拉利昂測試 – AndrewK