Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macOs bash/terminal command to open terminal, change directory and run command

I am writing what I assume is pretty easy bash script file. Although I cannot seem to do the following combination:

open new terminal instance > cd to directory > run command in that terminal instance

I got as far as:

open -b com.apple.terminal /path/I/want/

but if I try something like:

open -b com.apple.terminal /path/I/want/ && /path/to/command someCommand

It runs in the original window instance and not the new one. Tried some other variations of that as well with no success

like image 411
NicholasByDesign Avatar asked Oct 19 '25 11:10

NicholasByDesign


1 Answers

I managed to solve this with the following:

osascript -e "tell application \"Terminal\" to do script \"cd /directory/to/open && /path/to/command command\""

like image 58
NicholasByDesign Avatar answered Oct 21 '25 01:10

NicholasByDesign



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!