Bluetooth aktivieren

M

macwoif

Mitglied
Thread Starter
Dabei seit
11.12.2003
Beiträge
38
Reaktionspunkte
0
Hallo,

Wie kann man mit applescript bluetooth aktivieren?
hintegrund: möchte isync automatisiert ablaufen lassen und bräuchte dazu aktiviertes bluetooth...

danke,
macwoif
 
Unabhängig der Lösung des Problems wissend, darf man erfahren wozu Sie Bluetooth ein-, beziehungsweise ausschalten wollen ?
Ist es nicht irrelevant ob betreffende Funktion an, respektive aus ist?
Denken Sie an einen sicherheitstechnischen Aspekt, oder woran ist Ihnen dabei gelegen ?

In diesem Sinne

Smartcom
 
Nun...

Bluetooth ist bei mir aus Stromspargründen normalerweise aus und muss bei einem Sync jedesmal aktiviert und danach deativiert werden - das hätte ich gerne automatisiert.

Mittlerweile ist mir das ganze auch gelungen, mit Hilfe von GUI-Scripting. Ein Musterscript findet sich dazu im Apple Discussion Forum, bei Bedarf kann ich die Lösung gerne posten.

grüße
macwoif
 
Das wäre wohl hilfreich um eventuelle, später aufkommende Fragen gleichen Beweggrundes zu unterbinden. ;)

Code stellt man übrigens hier mit [CODE_] …Code-Fragment… [/CODE_] dar.
Unterstriche weglassen. ;)

In diesem Sinne

Smartcom
 
bidde sehr...

das delay muss gegebenfalls angepasst werden.

Code:
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
	try
		click bt_menu
		tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
			click
		else
			error
		end if
	on error
		repeat with x in menu bar items
			click x
			try
				if the title of the first menu item of the front menu of x starts with "Bluetooth" then exit repeat
			end try
		end repeat
		set bt_menu to x
		try
			tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
				click
			else
				error
			end if
		on error
			click bt_menu
			display alert "Bluetooth Menu Extra not found."
		end try
	end try
end tell
--
--
--
tell application "iSync"
	
	activate
	synchronize
	delay 80
	quit
	
end tell
--
--
--
tell application "System Events" to tell the front menu bar of process "SystemUIServer"
	try
		click bt_menu
		tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
			click
		else
			error
		end if
	on error
		repeat with x in menu bar items
			click x
			try
				if the title of the first menu item of the front menu of x starts with "Bluetooth" then exit repeat
			end try
		end repeat
		set bt_menu to x
		try
			tell the second menu item of the front menu of bt_menu to if title contains "Bluetooth" then
				click
			else
				error
			end if
		on error
			click bt_menu
			display alert "Bluetooth Menu Extra not found."
		end try
	end try
end tell
 
macwoif schrieb:
bidde sehr...

Das "delay" muss gegebenenfalls angepasst werden.
Vorbildlich, mein Herr. :D

In diesem Sinne

Smartcom
 
Gibt es dazu evtl. ein Update für Big Sur?
 
Hallo,

meiner Meinung nach ist blueutil nach wie vor der beste Weg, um Bluetooth per Skript zu de/aktivieren.
https://github.com/toy/blueutil


Ansonsten per UI-Skript....

Sofern die Bluetooth Menüleisten Erweiterung aktiviert ist:

Code:
tell application "System Events"
    tell process "ControlCenter"
        set _theBluetoothToggle to menu bar item "Bluetooth" of menu bar 1
        click _theBluetoothToggle
        --delay 0.2
        set _theBluetoothState to checkbox "Bluetooth" of group 1 of window "Kontrollzentrum"
        click _theBluetoothState
    end tell
    key code 53
end tell

Ist Bluetooth nicht in der Menüleiste angezeigt, so erreicht man es direkt über das Kontrollzentrum:

Code:
tell application "System Events"
    tell process "ControlCenter"
        set _theControlcenter to menu bar item "Kontrollzentrum" of menu bar 1
        click _theControlcenter
        --delay 0.2
        set _theBluetoothState to checkbox "Bluetooth" of group 1 of group 1 of window "Kontrollzentrum"
        click _theBluetoothState
    end tell
    key code 53
end tell



Gruß
 
Hallo,

meiner Meinung nach ist blueutil nach wie vor der beste Weg, um Bluetooth per Skript zu de/aktivieren.
https://github.com/toy/blueutil

...
Meiner Meinung nach auch. Ein Script könnte so aussehen:
Code:
set blueutilpath to quoted form of "/path/to/blueutil"
if last word of (do shell script blueutilpath & " status") = "on" then
    do shell script blueutilpath & " off"
else
    do shell script blueutilpath & " on"
end if
 
Zurück
Oben Unten