If you're serious about terminal work, I would suggest looking at tmux, especially as new builds of iTerm 2 come with it precompiled in (though I use the 'vanilla' version). In your case, if you were using tmux you could detach the current session from the window you're in, and then reattach in a new one (i.e., full screen), or just have multiple windows attached to the same session. There are some other advantages to using tmux, but I'm sure you'll discover them as you're using the program more.
Alternatively, have iTerm show the tab bar even if you only have one tab (make sure Appearance > Hide tab bar…
is unchecked), and then you can 'pull' the tab out into its own window to continue using it.
Here it is:
/usr/bin/osascript -e 'tell application "Safari"' -e "activate" -e 'tell application "System Events"' -e 'keystroke "f" using {control down, command down}' -e "end tell" -e "end tell"
Here it is in a clearer form (but you can't run it this way):
/usr/bin/osascript -e "tell application \"Safari\""
-e "activate"
-e "tell application \"System Events\""
-e "keystroke \"f\" using {control down, command down}"
-e "end tell"
-e "end tell"
And this is it as formatted AppleScript:
tell application "Safari"
activate
tell application "System Events"
keystroke "f" using {control down, command down}
end tell
end tell
It works by first opening a Safari window if one is not currently open. Then it simulates the Control ⌃-Command ⌘-F keystroke which tells the Safari window to become full screen.
If you want to make the window the max-size it can be without becoming full screen (i.e. taking up all the space below the menu bar at the top):
tell application "Finder"
set desktopSize to bounds of window of desktop
end tell
tell application "Safari"
activate
set bounds of window 1 to desktopSize
end tell
Which would become this in Terminal:
/usr/bin/osascript -e "tell application \"Finder\"" -e "set desktopSize to bounds of window of desktop" -e "end tell" -e "tell application \"Safari\"" -e "activate" -e "set bounds of window 1 to desktopSize" -e "end tell"
For Chrome, do this:
tell application "Google Chrome"
activate
make new window
tell application "System Events"
keystroke "f" using {control down, command down}
end tell
end tell
So it would be this in Terminal:
/usr/bin/osascript -e "tell application \"Google Chrome\"" -e "activate" -e "make new window" -e "tell application \"System Events\"" -e "keystroke \"f\" using {control down, command down}" -e "end tell" -e "end tell"
Hope this helps!
Best Answer
I'd recommend not allocating any GUI elements until after the command line input is finished.
If you run your app from a non-fullscreen Terminal, you'll probably notice that the app launches in the Dock (even if no windows appear) before you finish entering your command line stuff. This is probably what's causing the Space-switch.