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?
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.
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
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?
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.
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.)
MY palette looks like this:
So – as you can see this task is not exactly simple, but it's not too hard either.