Skip to content

Instantly share code, notes, and snippets.

@kxalex
Created February 16, 2021 08:06
Show Gist options
  • Save kxalex/359a919dae86539d3b0e00bda324e5b5 to your computer and use it in GitHub Desktop.
Save kxalex/359a919dae86539d3b0e00bda324e5b5 to your computer and use it in GitHub Desktop.
AppleScript to choose network locations
# Quick access through fn^⌥⌘N hotkey (BetterTouchTool❤️)
set the_location to (choose from list (my switch_location("", true)) with prompt "Choose a Location to Activate:" OK button name "Activate")
if the_location = false then return
my switch_location(the_location as string, false) --of course you could hard code it: my switch_location("home", false)
on switch_location(the_location, return_locations)
tell application "System Events"
tell (item 1 of (processes whose frontmost = true))
tell menu bar 1
tell menu bar item "Apple"
tell menu "Apple"
tell menu item "Location"
tell menu "Location"
if return_locations = true then return name of menu items
click menu item the_location
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end switch_location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment