Hey Barry,
This AppleScript is just plain wrong in several respects.
Please see this post (and the thread in general).
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.)
MY palette looks like this:
So – as you can see this task is not exactly simple, but it's not too hard either.
-Chris