Skip to content

Instantly share code, notes, and snippets.

@mlambie
Created August 13, 2009 08:58
Show Gist options
  • Save mlambie/167056 to your computer and use it in GitHub Desktop.
Save mlambie/167056 to your computer and use it in GitHub Desktop.
-- Register to track if we need a new window or not
set tab_count to 0
-- The names of the screen sessions - change as necessary
set screen_names to {"tfg_1", "tfg_2", "tfg_3", "tfg_4"}
-- Make our settings globally available
global tab_count, screen_names
-- Mainline
on main()
set target_server to display dialog "Connect to:" with title "Target Server" with icon caution default answer "" buttons {"Cancel", "OK"} default button 2 giving up after 20
if length of (text returned of target_server) is not 0 then
tell application "Terminal"
activate
repeat with x in screen_names
set cmd to "ssh -t " & text returned of target_server & " 'screen -d -R " & x & "'"
my open_tab(cmd)
end repeat
end tell
else
display dialog "You didn't enter a server!" with icon stop buttons ["OK"] default button 1
end if
end main
on open_tab(cmd)
tell application "Terminal" to activate
my create_new_window_or_tab()
tell application "Terminal" to ¬
do script with command (cmd) in last tab of window 1
end open_tab
on create_new_window_or_tab()
if tab_count ≤ 0 then
tell application "Terminal" to do script ""
set tab_count to tab_count + 1
else
tell application "System Events" to ¬
tell process "Terminal" to ¬
keystroke "t" using command down
end if
end create_new_window_or_tab
-- Run the mainline
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment