I have created a simple script that takes some parameters as input, opens a new iTerm2 window and executes them.

The script is fairly simple:

on run argv

    set argList to {}
    repeat with arg in argv
        set end of argList to quoted form of arg
    end repeat
    set {TID, text item delimiters} to {text item delimiters, space}
    set argList to argList as text
    set text item delimiters to TID

    if application "iTerm" is running then
        tell application "iTerm"
            create window with default profile
        end tell
        activate application "iTerm"
    end if

    tell application "iTerm"
        tell current tab of current window
            set _new_session to last item of sessions
        end tell

        tell _new_session
            if (argList is not equal to "") then
                write text argList & " 2>&1"
            end if
        end tell
    end tell

end run

The script runs perfectly fine from the command line by typing for example

osascript iTerm2runCommand.scpt ls

Also with multiple parameters, the script works fine

osascript iTerm2runCommand.scpt touch testFile

Unfortunately when exporting it to an application using the Script Editor (by selecting export -> file format Application) the newly generated iTerm2runCommand.app is completely broken. Tried from the command line, and double-clicking; nothing happens. The icon in the Dock briefly appears but nothing happens.

Tried on Mojave 10.14.2.

You must log in to answer this question.

Browse other questions tagged .