I am using a MacOS osascript command in a shell script and I try to run the following command:
APPNAME=$@
if pgrep -x "$APPNAME" > /dev/null # checking if app is open
then
echo "Closing..."
osascript -e 'quit app $APPNAME'
else
echo "*** The app is not open"
fi
Ideally, the command would be osascript -e 'quit app "Calendar"' as an example of a working solution. However, I can't seem to insert a variable in-between ' ' quotation marks.
What would be a workaround?
osascript -e "quit app $APPNAME", an easy-to-read alternative, which might come handy if you want to do one day a mixture of interpolated and non-interpolated strings, isosascript -e 'quit app '"$APPNAME".osascript -e 'on run argv' -e 'quit app (item 1 of argv)' -e 'end run' "$appname"osascript -e 'quit app "'"$APPNAME"'"'. I just show the general principle of how to handle quoting. You need to apply this in the way it fits for your concrete usage case.