I am using a Mac running OSX Yosemite v.10.10.5.

When I try to run my shell script from my AppleScript, I get the following error message:

Error message at AppleScript Script Editor
error "sh: /Users/path/to/file/myShellScript.sh: Permission denied" number 126
cd /Users/myusername/Git/myproject/
git remote remove origin
do shell script "/Users/path/to/file/myShellScript.sh"

What am I doing wrong?


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.

  • What about embedding the Shell Script into the Apple Script file? How would you embed few lines of Shell Script into Apple Script? – Royi Apr 9 at 12:14

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

Play your code with osascript

osascript << EOF
tell application "Terminal"
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .