brock
11/21/2012 - 5:11 AM

iTerm / Sublime AppleScript

iTerm / Sublime AppleScript

tell application "System Events"
	# create an iTerm session if we dont have one
	if not (exists (processes where name is "iTerm")) then
		tell application "iTerm" to (make new terminal)
	end if
	
	tell application "iTerm"
		activate
		tell the current terminal
			set SublimeSessionName to "sublime"
			set SublimeSession to false
			
			# loop through all our iterm sessions looking for our sublime session			
			repeat with iTermSession in sessions
				if name of iTermSession is SublimeSessionName then
					set SublimeSession to iTermSession
					exit repeat
				end if
			end repeat
			
			# create the session if we cant find our beloved sublime session			
			if SublimeSession is false then
				set SublimeSession to (make new session at the end of sessions)
				tell SublimeSession
					set name to SublimeSessionName
					#set background color to "blue"
				end tell
			end if
			
			select SublimeSession
		end tell
	end tell
	
end tell