1

Using Applescript, is it possible to open a new Terminal and enter the command into the terminal but do not run it?

tell application "Terminal"
    do script "echo Hello"
end tell

This code will type the line echo Hello into the Terminal and run it. Can we avoid the execution?

1 Answer 1

1

Good case for System Events app and emulating keystrokes:

tell application "Terminal" to activate -- only needed if Terminal may not be running

tell application "System Events"        
    tell application process "Terminal"
        set frontmost to true
        keystroke "echo Hello"
    end tell        
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.