Since upgrading to Yosemite, has anyone else noticed a spinning gear in the menu bar when a macro executes an AppleScript? It doesn’t seem to interfere with the macro itself, but when I click the gear, there is a small pop-up window that claims the AppleScript in the macro has not run (which appears to be false). The gear is Script Monitor, apparently new with Yosemite. It also seems to slow my wifi connection to a crawl; when I force quit Script Monitor through Activity Monitor, my wifi connection went back to normal.
No, I haven’t seen this. I think I heard something about it when running Automator actions.
What kind of AppleScript is it? An applet or application, or just plain text within Keyboard Maestro?
Thanks for your quick response. Now that you mention it, it is a macro that runs an Automator workflow that runs an AppleScript to turn file sharing off when my MacBook Pro is not connected to my home wifi network or not (I have a companion macro that runs a similar workflow to turn it on when I’m at home). The behavior has not been consistent, but if what you’re hearing is in connection with Automator then that is probably where I ought to look next. The script itself is:
on run {input, parameters}
tell application "System Preferences"
activate
reveal anchor "Internet" of pane id "com.apple.preferences.sharing"
end tell
tell application "System Events"
tell process "System Preferences"
tell table 1 of scroll area 1 of group 1 of window 1
tell (1st row whose value of static text 1 is "File Sharing")
if (value of checkbox 1) = 1 then
click checkbox 1
end if
end tell
end tell
end tell
end tell
quit application "System Preferences"
return input
end run
Is there any reason you need to use Automator for this and not simply run the AppleScript from Keyboard Maestro.
That said, the AppleScript will require accessibility permissions, and I’m not sure how well that works in the Mavericks/Yosemite world of per-app accessibility requirements.
Hey Jared,
A macro employing Automator to run an AppleScript is far too roundabout unless Automator provides key functionality unavailable to AppleScript (as happens occasionally) — as Peter mentioned Keyboard Maestro runs AppleScripts just fine on its own.
Let's see if we can speed this task up a bit...
Yep; `networksetup` in the shell can access AirPort and toggle it on/off far more expeditiously than System Events.
-Chris
#!/bin/sh
AIRPORT_STATUS=$(networksetup -getairportpower en1)
if [ "$AIRPORT_STATUS" = "Wi-Fi Power (en1): On" ] ; then
networksetup -setairportpower en1 off
else
networksetup -setairportpower en1 on
fi
AirPort { Toggle On:Off }.kmmacros (1.8 KB)
Peter - Thanks again. I don’t remember offhand why I set it up through an Automator workflow originally – I probably copied the AppleScript from someone who posted it online that way – but it works perfectly when executed directly through KM, with removal of the first line (starting “on run”) as the only change needed.
Chris - Thanks for the suggestion. If I ever want to use KM shut down the Airport entirely, I expect I’ll come back and grab that script too.