Applescript enable-disable wifi Safari I figured out a command to enable/disable wifi.

networksetup -setairportpower en0 on
networksetup -setairportpower en0 off


Now, I was wondering how to combine it in AppleScript in a way that when Safari opens wifi is turned on and when Safari closes wifi is turned off?
Run EDITOR=nano crontab -e and add a line like this:

* * * * * pgrep -qx Safari&amp;&amp;networksetup -setairportpower en0 on||networksetup -setairportpower en0 off

The command is only run once every minute though.

You could also save this plist as ~/Library/LaunchAgents/safariwifi.plist:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
  &lt;key&gt;Label&lt;/key&gt;
  &lt;string&gt;safariwifi&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;bash&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;while sleep 10;do pgrep -qx Safari&amp;amp;&amp;amp;mode=on||mode=off;[[ $last != $mode ]]&amp;amp;&amp;amp;networksetup -setairportpower en0 $mode;last=$mode;done&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Then run launchctl load ~/Library/LaunchAgents/safariwifi.plist.