답변:
이런 식으로 Bluetooth를 사용하기위한 직접적인 AppleScript 사전이없는 것 같습니다.
GUI 스크립팅을 사용하면 기본적으로 Mac OS의 접근성 기능을 사용하여 메뉴 항목 등을 선택할 수 있습니다.
GUI AppleScript로 시작하는 방법에 대한 훌륭한 글은 MacOSAutomation.com에서 볼 수 있습니다 .
지속적으로 변경되는 항목 목록이 있으면 GUI 자동화가 어려울 수 있지만 일반적으로 동일한 블루투스 항목 목록이 연결되어 있으면 동일하게 유지됩니다.
그런 다음 Alfred를 통해이 AppleScript를 호출 할 수 있습니다.
http://macscripter.net/viewtopic.php?id=38559
위의 링크에는 방금 업데이트 한 아주 멋진 스크립트가 있습니다. blueutil [ git repo ] [ website / binaries ]를 사용합니다.
블루투스 사용 :
-- Enable Bluetooth and Connect to iPhone
property blueutilPath : "/opt/local/bin/blueutil"
-- Turn on bluetooth.
if execBlueutil("status") contains "Status: off" then
execBlueutil("on")
connectDevice()
doGrowl()
end if
on execBlueutil(command)
set res to do shell script blueutilPath & " " & command
if res contains "Error" then
display dialog res
quit
end if
return res
end execBlueutil
-- Connect Device
on connectDevice()
tell application "System Preferences"
activate
set AppleScript's text item delimiters to "."
set current pane to pane "com.apple.preference.network"
set winNetwork to "Network"
set btooth to "Bluetooth"
tell application "System Events" to tell process "System Preferences"
set theRow to row 1 of table 1 of scroll area 1 of window winNetwork whose value of static text 1 contains btooth
select theRow --clicks the bluetooth row
--If Bluetooth is already connected, the button will say Disconnect, so we don't want to turn it off:
try
click (button 1 of group 1 of window winNetwork whose title is "Connect")
end try
end tell
tell application "System Preferences"
quit
end tell
end tell
end connectDevice
on doGrowl()
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
set the allNotificationsList to ¬
{"Bluetooth Setting"}
set the enabledNotificationsList to ¬
{"Bluetooth Setting"}
register as application ¬
"AppleScript - Bluetooth" all notifications allNotificationsList ¬
default notifications enabledNotificationsList
notify with name ¬
"Bluetooth Setting" title ¬
"Bluetooth is On & iPhone Connected" description ¬
"Bluetooth has been enabled with iPhone tethered." application name "AppleScript - Bluetooth" icon of file (path to me)
end tell
end if
end doGrowl
블루투스 비활성화 :
property blueutilPath : "/opt/local/bin/blueutil"
-- Turn off Bluetooth.
if execBlueutil("status") contains "Status: on" then
execBlueutil("off")
doGrowl()
end if
on execBlueutil(command)
set res to do shell script blueutilPath & " " & command
if res contains "Error" then
display dialog res
quit
end if
return res
end execBlueutil
on doGrowl()
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
set the allNotificationsList to ¬
{"Bluetooth Setting"}
set the enabledNotificationsList to ¬
{"Bluetooth Setting"}
register as application ¬
"AppleScript - Bluetooth" all notifications allNotificationsList ¬
default notifications enabledNotificationsList
notify with name ¬
"Bluetooth Setting" title ¬
"Bluetooth Off" description ¬
"Bluetooth has been disabled." application name "AppleScript - Bluetooth" icon of file (path to me)
end tell
end if
end doGrowl