Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Trying to execute a command from applescript.

tell application "iTerm 2"
    make new terminal
    tell the current terminal
        activate current session
        launch session "Default Session"
        tell the last session
            write text "cd ~/Downloads; clear; pwd"
        end tell
    end tell
end tell

Referencing this question: How do I set up an AppleScript to open a new iTerm2 tab and change the directory?

This doesn't seem to work for me. In fact, neither the exec command or the write text commands seem to work - the text is placed on the command line, but the newline isn't added to actually execute it. My suspicion is that it's somehow writing the text before the terminal is ready for input...

share|improve this question
You ever figure this out? Having the same issue. – Matt Love Nov 2 '13 at 21:33
Yeah, somewhat - see below. – pschuegr Nov 4 '13 at 18:44
up vote 1 down vote accepted

I got this working in the end but it was after so much trial and error that I can't remember exactly what made it work. But I can tell you two useful things: 1) I downgraded to iTerm 1.0.0 and 2) here is the code.

on run {input, parameters}
    tell application "iTerm 2"
        if (count of terminals) = 0 then
            set t to (make new terminal)
            set t to current terminal

        end if
        tell t
            set s to (make new session at the end of sessions)
            tell s
                exec command (("vim \"" & POSIX path of first item of input as text) & "\"")
            end tell
        end tell
    end tell
end run
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.