Home > database >  Run 2 commands in applescript/osascript with variable
Run 2 commands in applescript/osascript with variable

Time:08-16

I am trying to run 2 commands stored in a variable with osascript

This is my start.sh

currentDirectory="cd $(pwd) && npm run start"

echo $currentDirectory

osascript -e 'tell application "Terminal" to do script '"${currentDirectory}"''

I am getting this as the output

sh start.sh
cd /Users/Picadillo/Movies/my-test-tepo && npm run start
83:84: syntax error: Expected expression but found “&”. (-2741)

CodePudding user response:

The argument to do script needs to be in double quotes.

osascript -e 'tell application "Terminal" to do script "'"${currentDirectory}"'"'

You should also put the argument to cd in quotes, in case it contains spaces.

currentDirectory="cd '$(pwd)' && npm run start"
  • Related