Switch On/Off Bluetooth

Hey @Athena,

Look at the syntax for blueutil by running the following line in the Terminal:

blueutil -h

If you run blueutil -p you'll get either a 1 or a 0 for the on/off status of BlueTooth.

With that as a start you have the means to create a macro that toggles BlueTooth just as you wanted.

Use an Execute a Shell Script action to save the output of the above to a a variable.

Test the variable with a If Then Else action.

Proceed with the correct actions based on your test.

This kind of logic isn't overly difficult once you've done it a few times.

On the other hand in the macro below I've done all the work in the shell except for the notifications.

BlueTooth -- Toggle On-Off -- Using blueutil v1.00.kmmacros (7.6 KB)

Now – let's go back to that help screen for blueutil and take notice of the toggle option.

If I was willing to forego BlueTooth status notifications I could do the whole job with two lines. (One if I want to use the full path to the exe, or if I have an ENV_PATH variable properly set up in Keyboard Maestro.)

export PATH=/usr/local/bin:$PATH;
blueutil -p toggle

Enjoy.

-Chris

1 Like