Skip to content

Instantly share code, notes, and snippets.

@SamRaymer
Created January 8, 2011 03:23
Show Gist options
  • Save SamRaymer/770505 to your computer and use it in GitHub Desktop.
Save SamRaymer/770505 to your computer and use it in GitHub Desktop.
Opens a new SSH connection and tunnels your traffic through it. For OS X. Uses Apple's Terminal. Thanks/sorry to Jon Gales, Jacob Rus.
--Set these constants!
--Change username to the username on the server you want to use
set userName to "uwnetid"
--Change myHost to a host you have SSH access to if you don't have uw access
set myHost to "dante.u.washington.edu"
--This is kind of the universal default socks proxy port,
-- but feel free to change it.
set socksPort to 8080
-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: {"Finder", "View", "Arrange By", "Date"}
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ¬
((process appName)'s (menu bar 1)'s (menu bar item topMenu)'s ¬
(menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) ¬
of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
--This portion of script by Sam Raymer (c)2011
tell application "Terminal"
activate
set openProxy to false
repeat with win in windows
repeat with curtab in win's tabs
if curtab's title displays custom title then
if curtab's custom title is "FireMiddleFinger" then
set openProxy to true
end if
end if
end repeat
end repeat
if not openProxy then
-- talk to the new terminal
-- make a new session
my menu_click({"Terminal", "Shell", "New Tab", "Pro"})
set mytab to the first window's selected tab
-- talk to the session
tell mytab
-- set some attributes?
-- execute a command
set cmd to "ssh " & userName & "@" & myHost & " -D " & socksPort
do script cmd in mytab
set mytab's custom title to "FireMiddleFinger"
--exec command "/bin/ssh"
end tell -- we are done talking to the session
end if
end tell
--Auto SOCKS Enable by Jon Gales www.jongales.com
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
get properties
tell process "System Preferences"
tell window "Network"
-- Selects the active network connection
tell table 1 of scroll area 1
click row 1
end tell
--Select the Advanced button
click button 11
--Select the Proxies tab
tell tab group 1 of sheet 1
-- delay 1
click radio button 6
tell group 1
tell table 1 of scroll area 1
set selected of row 6 to true
click checkbox of row 6
if value of (checkbox 1 of row 6) is 1 then
set outStr to "You Turned SOCKS ON"
else
set outStr to "You Turned SOCKS OFF"
end if
end tell
end tell
end tell
tell sheet 1
click button "OK"
end tell
end tell
tell window "Network"
click button "Apply"
end tell
end tell
end tell
tell application "System Preferences"
quit
end tell
-- Voice status of SOCKS Proxy settings
say outStr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment