How to run a shell script from an AppleScript?
To not get that error, you need to make myShellScript.sh
executable.
In a Terminal, use the following command:
chmod u+x /path/to/file/myShellScript.sh
Also, you should add a shebang to the top of the script.
Example: #!/bin/bash
Note: Use the appropriate shebang for the shell you want to process your script.
If you do not want to make the script executable, although I can't see a reason one wouldn't want to, you can run it in AppleScript as in the following example:
do shell script "bash /path/to/file/myShellScript.sh"
Note: If you want to use sh
over bash
, just substitute it in the command and the shebang.
You can embed your shell script within AppleScript calling bash
with a heredoc
.
do shell script "/bin/bash -s <<'EOF'
cd /Users/myusername/Git/myproject/
/usr/bin/git remote remove orig
EOF"
Play your code with osascript
osascript << EOF
tell application "Terminal"
activate
end tell
EOF