June 18, 2022

oascript to run new terminal with command

Запуск новой вкладки iTerm2 с командой из консоли

#!/usr/bin/osascript

on run argv
    if exists (window 1 of application "iTerm") then
        tell application "iTerm"
            set AppleScript's text item delimiters to " "
            tell current window
                create tab with default profile
                tell the current session
                    write text argv as string
                end tell
            end tell
        end tell
    else
        tell application "iTerm"
            activate

            set AppleScript's text item delimiters to " "
            try
                tell current window
                    tell current session
                        write text argv as string
                    end tell
                end tell
            on error execution
                set newWindow to (create window with default profile)
                tell current session of newWindow
                    write text argv as string
                end tell
            end try
        end tell
    end if
end run 

Запуск нового терминала с командой из консоли

on run argv
   tell app "Terminal" 
   set AppleScript's text item delimiters to " "
        do script argv as string
        end tell   
end run 

Например terminal “ls | grep Do”