I am new to shell script and recently wrote a script to open a new terminal window and run defined functions via osascript with "do shell script", but the result showed the command not found. My script is as below:
#!/bin/bash
hello() {
echo "Hello World"
}
openNewWindowAndRun() {
osascript -e "
tell application \"Terminal\"
activate
do script \"$1\"
end tell
"
}
openNewWindowAndRun hello
I have also tried to directly call the hello
function in the openNewWindowAndRun
but didn't get any luck:
#!/bin/bash
hello() {
echo "Hello World"
}
openNewWindowAndRun() {
osascript -e "
tell application \"Terminal\"
activate
do script \"hello\"
end tell
"
}
openNewWindowAndRun
When I ran the script, it opened the new window successfully but showed the error message:
Does anyone know which part I missed here? Is it possible to pass a defined function as a parameter to osascript? If anyone can give me a hand, that would be great!