How to automatically open a terminal window and automatically run a command mac

Last modified date

Comments: 0

Contents

Problem

You want to write a command that can open a new terminal window and then automatically run a command.

Solution

The simplest way to do this on a mac is to use the osascript command to launch a new terminal window and then run a command.

For example, the simple script below will open a new terminal window and then echo ‘Hello, World!’ to the console.

osascript -e 'tell app "Terminal"
do script "echo Hello, World!"
activate
end tell'

JakTech

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.