§(Toggle Wi-Fi).app
Applescript Tutorial
| (* |
| Installation instructions |
| Run as an Application: |
| 1) Open AppleScript Editor and create a new script |
| 2) Paste this file into it |
| 3) Save name it '§(Toggle Wi-Fi)' |
| - Or substitute '§' for a symbol that you can press with a single key |
| 4) Put it in Applications/Utilities |
| 5) Wait until Spotlight has indexed it |
| 6) Launch using CMD+Space (spotlight) then the symbol you chose + Enter |
| 7) Profit! |
| Run as a Service: |
| 1) Go to Automator and create a new Service |
| 2) Select Action 'Run AppleScript' |
| 3) Select that 'Service receives no input in any application' |
| 4) Replace '(* Your script goes here *)' with the contents of this file |
| 5) Save the Service (CMD+S) |
| 6) Enter a proper name for the service (how about 'Toggle Wi-Fi') |
| 7) Exit Automator |
| 8) Open System Preferences/Keyboard/Shortcuts |
| 9) Select Services |
| 10) Find your Service in the list |
| 11) Assign it a shortcut (I chose F5) |
| 12) Profit! |
| MIT License |
| THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| *) |
| set device to do shell script 'networksetup -listallhardwareports | awk '$3'Wi-Fi' {getline;print}' | awk '{print $2}' |
| set power to do shell script 'networksetup -getairportpower ' & device & ' | awk '{print $4}' |
| if power is equal to 'on' then |
| set power to 'off' |
| else |
| set power to 'on' |
| end if |
| do shell script ('networksetup -setairportpower ' & device & ' ' & power) |
| (*If running as an Application you'll want to uncomment the line below to exit the script after it is done*) |
| (*quit me*) |
AppleScript Mac OS X. Topic Replies Views Last post; Sticky. Remove duplicate lines from AppleScript variable by johncatalano. 6: 479: 2020-10-21 08:27:58 pm. The above script causes automator's applescript to hang if a domain is not available. It works fine in AppleScript Editor if you add -t X where X is a number of seconds ping should time out otherwise it'll hang indefinitely as well.
commented Mar 5, 2018

commented Jan 23, 2019

commented Jan 24, 2020

Applescript Download File
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
