Macro to Toggle Bluetooth and Wireless?

I have one macro to toggle wifi on/off and another for BT. I'd like to combine them with one macro to trigger both together. (unless there's a simpler way to accomplish this). Both run simple shell scripts; both work alone.

This doesn't work:

Is there a way to get this to go? Ideally, I'd trigger it (eventually) with a BetterTouchTool button on the TouchBar but that's another story. Thanks.

I presume ⌃\ and ⌃] are your triggers for the two macros in question? You could try the Trigger Macros by Hot Key action:

image

But I think what you probably want instead is to just have this Toggle Internet macro run two Execute a Macro actions.

Did you know that at the top of your macro you can have two (or more) triggers for hot keys? Can't you just add two triggers for each of your two macros which work separately? Is this clear or do you need screenshots of what I'm saying?

Not sure what you mean. Each macro controls one function, either BT on/off or Wifi on/off. I need one macro to control both macros.

Yes each macro controls one function. But you can have a single keypress trigger two macros at the same time by adding extra triggers at the top of the macro. Or, at least that's how I think it should work. I've never tested that. It will look like this:

If you have two hotkey triggers for two different macros with identical trigger keys for each macro, wouldn't that solve your problem?

Actually I don't think you need two triggers. You just need the same trigger for two different macros. Is that now correct?

Am I ever dumb today. It didn't work. I'm only right 80% of the time. Let me try again. Sorry about the mistake.

Ok try it this way. I'm sorry for being dumb today.

This new solution will call both macros, sequentially. This is more appropriate than generating keystrokes. Does this help you out? (Use Ctrl-W or whatever you want instead of the F5 key that I used.)

THanks! Sounds good. But I tried the solution of "do script [MACRO NAME]" x2, one for each of the two macros—a solution you suggested, I saw, from the WIKI. And that does the trick. Perhaps not entirely economical, but works,

Our messages crossed. Yes. That was the previous poster's idea too. tx!

I did read GG's post, but I must have been really REALLY really dumb today because I didn't understand what he was saying.

@ gglick
Execute a Macro was the solution. Merci.

1 Like

Would you mind sharing your two macros? I would like to do the same thing.

I think you were talking to jipnet, because the two macros that I included screenshots of were just empty stubs.

Here are the ones I made and that seem to work just fine (both controlled by the Toggle Internet macro with one keystroke combination)

Toggle BT.kmmacros (2.4 KB) Toggle Internet.kmmacros (2.4 KB) Toggle WIFI ON:OFF.kmmacros (2.0 KB)

Here are screenshots with code:

ToggleWiFi:

Execute AppleScript
set status to do shell script "networksetup -getairportpower en0"
if status ends with "On" then
  do shell script "networksetup -setairportpower en0 off"
else
  do shell script "networksetup -setairportpower en0 on"
end if

Toggle BT:

Execute AppleScript
tell application "System Preferences"
   reveal pane id "com.apple.preferences.Bluetooth"
   -- activate

   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

end tell

ToggleInternet (commands both synchronously; NB: both BT and WiFi must be on or off for this command to turn off or on both)

To add this as a Better Touch Tool button on the Touch Bar (allows you to tap it to trigger the Super-Macro that triggers the two sub-macros), you simply configure a button like this (or as you wish):

2 Likes

If you @jipnet want to save the shortcut for your macro and want to trigger the macro via the Touch Bar with BetterTouchTool, then use the KM Macro AppleScript .
Could even reduce my shortcuts in KM by 90 percent.

Actually, that is what I did, sort of:

appears as a red button on the Touch Bar, acts as a toggle.

Not sure what "the KM Macro AppleScript" refers to, and not sure how that could reduce KM shortcuts by 90% (the space on the Touch Bar is quite limited).

1 Like

I shouldn't try speak for another person (that won't stop me from trying) but I think when he said "KM Macro AppleScript" he probably meant "the KM action Execute AppleScript", ie,

image

I'm not sure how he concludes that we can reduce shortcuts by 90%. Perhaps he meant if we code things in Applescirpt we can reduce our code in KM proportionately. Sure. If you eat more Apples (AppleScript) you can eat fewer Kiwis (Keyboard Maestro). But you still need to eat the same amount of fruit.

1 Like

Hi @jipnet and @Sleepy, at the beginning I also assigned shortcuts in KM and then used them in BTT to set up a touch gesture.
Since this has led to overlaps with the shortcuts over time, I also changed the use of the AppleScripts included in the macros. I now use it in BTT and save myself the trouble of working with random shortcuts :wink:

I had a post here once about it:

In my post I explain how to create BTT gestures with the mouse or trackpad. You @jipnet must select then in the BTT menu only the carrier for the Touch bar.

I downloaded your three macros from above, and they work fine here, too.

If you want to launch the master macro (Toggle Internet) from BTT, then just use the same method you are already using for launching the two sub macros from the master macro: via AppleScript.

You find the the premade AppleScript to launch your master macro in the “Or by AppleScript” popup:

19-pty-fs8

Then you paste that script to BTT here:

22-pty-fs8

…and set the BTT trigger you want.


BTW, to launch the sub macros from your master macro, you can also make use of the Execute Macro action:

59-pty-fs8
It is made for such cases, so no need to use an AppleScript action here.

1 Like

Hello @Tom, if you are interested, I have a macro with which you can save yourself the manual copy & paste of the AppleScript between KM and BTT.

In KM your macro manners (blue) and trigger the macro. If you have selected the AppleScript action in BTT, simply press the Space key and the AppleScript will be inserted.

2019_07_13_Support_1

UUID AS.kmmacros (24,6 KB)
UUID%20AS

Thanks for the idea. Currently I don’t use BTT, but this may change in the future.


BTW, there is an easier way to get the UUID of a macro:

tell application id "com.stairways.keyboardmaestro.editor"
  selectedMacros
end tell

35-pty-fs8

_[demo] Get ID(s) of Selected Macro(s).kmmacros (3.0 KB)

1 Like