Macro to Toggle Bluetooth and Wireless?

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

As always many thanks for your tip @Tom :+1:
I've put this in my macro.

I know @Tom that you also use Launchbar to trigger KM macros. Can I improve my macro? Does using the KM URL or the KM AppleScript make a difference?

2019_07_13_Support_1

Actions.kmmacros (51,9 KB)

Thanks Tom. There are obviously many ways to achieve the same goal.

I just noticed that the flaw with this method (and any proposed so far) is that to toggle both on or off, both must be in the same initial state (either on or off). Otherwise, one will go on and the other off. In other words, the solution is really "analogue" and not fully "digital." (no doubt due to the scripts that do the toggling, which I found on the web ready made)

THanks. I will explore these tips in due time. Right now I have a fat red button on my control strip that performs the combined action as scripted in KM, making it a snap to turn on or off the WiFi and BT. (I read that thieves can "sniff" BT and WiFi signals in a laptop in a car, so I want to deprive them of this opportunity in as mindless a way as I can remember.)

I haven't played with BTT folders, but I imagine you can drill down several levels without leaving the keyboard. But at some point, a floating palette might be simpler (alas, not so useful in a laptop format where screen real estate is limited—though your disappearing palette may take care of that too)

1 Like

Indeed, I thought the same. Especially your “Toggle BT” macro is rather fragile, due to its heavy reliance on UI AppleScripting.

Once one macro off means you are out of sync. So maybe better to create macros to enable and disable the stuff. Not toggling.

Well, good catch, but that can be fixed by an IF statement, such as "If Wireless Network BELL101 is connected then DISABLE both networks else ENABLE both networks." That's probably an improvement. But some people might prefer toggling both, which can be done with two IF statements.

I know, you are a big fan of chained GUI actions (clicking buttons, selecting menu items, …). Me not so much :sweat:

What about this:

Not completely “automized”, but dead simple.

If you really want to create dedicated LB actions to launch KM macros, then I would simply duplicate an existing one (in Action Editor, right-click on an action), adapt the name and paste the UUID into the script.
Once again, not automized. But not much gain by “automizing” it. Especially not when automizing it with a fragile GUI macro. (I know, Action Editor is not scriptable, but there isn’t much reason to make it scriptable.)

1 Like

Hi @jipnet, thanks for posting these. When you have a moment, would you mind editing your post to include screenshots of the macros? I’m asking for me, but it’s also a good rule of thumb to do this whenever posting a macro: it’s really helpful for others to be able preview what they’ll be downloading, or even save them the effort if they can see from a visual that it’s not what they were looking for.

[ If you want to be super duper, then you can also copy any scripting code used in any macros you upload, and include them as formatted code blocks under the screenshots, but this is less important. It can, however, benefit you should someone skim a post and notice something that wouldn’t have been caught otherwise. ]

Of course. So glad to provide, finally, something in return to this incredibly helpful forum.

I'll see if I can't edit the previous post.

Done. But I don't know how to make formatted code blocks unless it's by using three ``` before and after as above (after searching for this formatting command)

1 Like

Thanks a lot. That's awesome.

There are three options of which I'm aware:

  1. Indenting a line with 4 (or more) spaces will turn that line into a code snippet that spans the width of the post. Subsequent lines that are either blank or indented 4 (or more) spaces will be added and merged to form a code block. The block ends with the last, non-blank, indented line.

  2. When typing a post, the editing area has a toolbar:


    If you select a block of text first, then click the button shown, it indents every line by 4 spaces, thus creating a code block.

  3. The simplest way, I find, is, as you found, by opening and terminating a block of text using three backticks, ```. The opening set can, optionally, specify the language that is used to help highlight its syntax appropriately, e.g.:

    ```javascript
    factorial = (x) => {
        return (x==0) ? 1 : x * factorial(x-1);
    }
    ```
    

    will be formatted and highlighted as:

    factorial = (x) => {
        return (x==0) ? 1 : x * factorial(x-1);
    }
    

    The language identifier is often not needed as it's typically detected automatically. But common identifiers include: applescript, javascript, html, shell. Your code blocks suffered the annoying consequence of having the browser attempt to paste the code with the formatting style information that was copied along with the text itself. I forget how to avoid this from happening.

1 Like

Found it: you copy the code in KBM not by command-C but by the "copy" command in the gear that controls the code entry in the macro. And the ``` before and after. tx

Some laptops come with “Wi-Fi” function keys or switches that can quickly enable or disable your Wi-Fi. If your PC doesn’t have one of these, though, you can make one with the tools built into Windows.

You’ll need to start by creating a desktop or start menu shortcut. Once you’ve done that, you can invoke it with a keyboard shortcut, if you like. shareit apk

Thanks. I use Macs.