1

I wrote a program that I want to execute in 30 terminal tabs.

So I have this shell program:

for i in {1..29}
do 
    osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down'
done

And for every terminal windows just opened I want to do something like:

cd "Folder {i}"
python3 script.py

How can I achieve this?

1 Answer 1

1

As you are opening a new tab this becomes the front window, so just tell the front window to execute a script, changing the folder as necessary.

for i in {1..29}; do     

osascript -e 'tell application "Terminal" to activate' -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' -e "tell application \"Terminal\" to do script \"cd folder$i ; script.py\" in window 1"

; done

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

This works, I almost figured it out myself, but I didn't know there was such thing as a script keyword. Thank you Tom!

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.