Marcel Braasch
Marcel Braasch

Reputation: 1183

How to automate program execution using bash shell

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?

Upvotes: 1

Views: 43

Answers (1)

tomgalpin
tomgalpin

Reputation: 2099

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

Upvotes: 1

Related Questions