I have a command line application running on OSX that would like to create several tabs in the current window using AppleScript.
How can I tell if my program is running in Terminal, iTerm, or another terminal program?
The $TERM_PROGRAM
env var is set to iTerm.app
or Apple_Terminal
so you can determine which AppleScript cmds to run if you pass it as an arg to osascript
(assuming your shelling to osascript
)
osascript ThisScriptName.scpt $TERM_PROGRAM
--osascript ThisScriptName.scpt $TERM_PROGRAM
on run {TermType}
if (TermType = "iTerm.app") then
-- iTerm.app :-P
tell application "iTerm"
tell current window
tell current session
set newSession to (split horizontally with default profile)
end tell
end tell
end tell
else if (TermType = "Apple_Terminal") then
-- Terminal.app
tell application "Terminal"
do script "open 'https://iterm2.com/downloads.html'" in window 1
end tell
else
-- Unknown terminal application
return "Really? Not using iTerm.app or Terminal.app"
end if
end run