Does KM support multiple icons for a macro on a palette?

Does KM support multiple icons for a macro on a palette?

Specifically, how could I assign one icon (dimmed bluetooth) to display on a macro palette when Bluetooth is turned off and a different icon (active bluetooth) to display on the same macro palette when Bluetooth is turned on?

Instead, would this need to be accomplished with two palettes, one for the off condition which displays when Bluetooth is off and a counterpart version for the on condition which displays when Bluetooth is on?

Thanks in advance for replies to this post!

I moved this to a new topic since it is quite a different question.

Keyboard Maestro supports “marking” a macro, which you can do with the Mark Macro action, which will put a tick mark on a macro. The same sort of tick marks that show in the Applications Palette when the application is at the front for example.

Alternatively, you can have two different macros with two different icons, and you can use the Set Macro Enable action to enable one and disable the other to “change” the icon.

Hi Peter,

Many thanks for your reply.

I'm using the following AppleScript script to turn Bluetooth on and off (without using or including the Bluetooth menu extra, due to my already filled menu bar).

tell application "Terminal"
   do shell script "/usr/local/bin/blueutil status"
   set _Result to the result
   if _Result is "Status: on" then
      do shell script "/usr/local/bin/blueutil off"
   else if _Result is "Status: off" then
      do shell script "/usr/local/bin/blueutil on"
   end if
   quit
   tell application "System Events"
      tell application process "Safari"
         set frontmost to true
      end tell
   end tell
end tell

I've looked at the help for Set Macro (https://wiki.keyboardmaestro.com/action/Set_Macro_or_Group_Enable) and played with it, but evidently am overlooking or not understanding something.

Could you (or someone else) please elaborate on how to configure one (or two) buttons on a KM palette so that when clicked, the above script executes and the button properly switches between my active and dimmed bluetooth icons?

Many thanks in advance.

Hey Barry,

This AppleScript is just plain wrong in several respects.

Please see this post (and the thread in general).

Switch On/Off Bluetooth

The Terminal is NOT required, and multiple uses of do shell script is inefficient.

If you're going to use Keyboard Maestro to run the script then you may as well run a pure shell script using a Execute a Shell Script action.

A more efficient AppleScript using blueutil v2.4.0 on macOS 10.12.6.

set shCMD to "/usr/local/bin/blueutil --power"
set blueToothPowerStatus to do shell script shCMD

if blueToothPowerStatus is "0" then
   do shell script "/usr/local/bin/blueutil --power ON"
else if blueToothPowerStatus is "1" then
   do shell script "/usr/local/bin/blueutil --power OFF"
end if

status is no longer an available keyword in recent versions of blueutil.

An even better way to run this via AppleScript is:

set shCMD to "
export PATH=/usr/local/bin:$PATH;

if [[ $(type -P blueutil) = '' ]]; then

   echo \"The command line utility 'blueutil' is missing!\"

elif [[ $(blueutil -p) = 1 ]]; then

   blueutil -p OFF
   echo \"OFF\"

else

   blueutil -p ON
   echo \"ON\"

fi
"
set blueToothPowerStatus to do shell script shCMD

And better still is to run the shell script by itself in an Execute a Shell Script action.

Safari Group ⇢ 1-Key Macros.kmmacros (11.3 KB)

There are two of these in the supplied .kmmacros file – one turns BlueTooth ON and the other turns it OFF. (Download and double-click the file to install -- you'll then have to move the macros to your preferred macro group.)

image

MY palette looks like this:

51
05

So – as you can see this task is not exactly simple, but it's not too hard either.

-Chris

1 Like

Hi Chris,

Many thanks for your time and helpful reply.

As your reply helpfully explains, my macro very well could be "wrong," but it does function without any errors or issues. :slight_smile:

Cheers,

Barry

P.S. Yes, I already had read the other thread about on/off bluetooth macros and posted there; Peter then moved my posting into this separate thread.

I have three utilities that I am trying to make toggleable via KM macros on a palette. The three utilities are Blueutil, Hides, and a pair of KM macros to enable/disable Accessibility System Setting's feature to ignore the built-in trackpad when a mouse is present.

Of the 3, only the KM macros for Hides function properly; i.e., when I click the Hides icon in the KM palette to enable Hides, Hides is enabled and the enabled icon displays in the KM palette; when I click the Hides icon to disable Hides, Hides is disabled and the dimmed icon displays in the KM palette. Perfect!

Blueutil—when I enable Chris Stone's Execute Shell Script posted above in my pair of KM macros, nothing happens (i.e., if Bluetooth was ON at the time of running the macro, Bluetooth remains on; if it was OFF at the time, Bluetooth remains off). When I instead enable the AppleScript script that I posted above, the KM macros function properly (they turn Bluetooth on and off). However, the icon on the palette remains the same (dimmed) rather than toggling between the dimmed one that accompanies the "Bluetooth Disabled" macro and the active one that accompanies the "Bluetooth Enabled" macro. :thinking:

KM macros for trackpad toggling—when the trackpad is enabled (i.e., the Accessibility feature is toggled off), both of my KM macros display their icons on the KM palette; when the feature is toggled on (so that the trackpad is disabled), only the off icon displays on the KM palette. If I click that icon, the trackpad becomes enabled (as expected) but both icons then display on the KM palette. :thinking:

When I look at each of the above three pairs of KM macros, comparing the pair for Hides (which functions properly) with the pair for Blueutil and the pair for toggling the trackpad, they look the same to me with regard to the elements that enable and disable the macros.

Could someone please guide me on fixing my Blueutil and trackpad toggling macros functioning and displaying their palette icons properly?

P.S. The Blueutil macros include an AppleScript script that has been updated for Blueutil v. 2.10; I previously had been using v.2.0.5

Bluetooth Disabled.kmmacros (7.8 KB)
Bluetooth Enabled.kmmacros (7.8 KB)
b1Toggle ON Ignore built-in trackpad when mouse is present.kmmacros (23.4 KB)
b1Toggle OFF Ignore built-in trackpad when mouse is present.kmmacros (23.4 KB)

You've updated your AppleScript to account for Homebrew's path change for Apple silicon machines, but you haven't updated the shell script. Change the first line:

export PATH=/usr/local/bin:$PATH;

...to

export PATH=/opt/homebrew/bin:$PATH;

And, for me at least, your "Enable/Disable" actions aren't set to target anything:

image

...although that may be a result of the import -- it helps if you post images of your macros alongside the files.

The trackpad macro seems to have the same issue -- "toggle OFF" enables one macro but isn't disabling anything:

Hello and many thanks for your reply.

Good catch, my mistake re: updating the AppleScript script's path to the new version of Blueutil.

Here are screen captures showing the relevant portion of my macros' enable/disable configurations, to address your helpful feedback. I don't know how come they are incorrect in the posted kmmacros files.