I am using git to manage a project that has a few binary files that need to be closed before being committed. So I need a git hook, that checks to see if the application that has these files open is running.

Here is the script I am using

#!/usr/bin/env osascript

tell application "System Events"
    set apps to the name of every process whose background only is false
end tell

if "Some App" is in apps then
    error "Some App is running. Can't commit until Some App is quit" number 5
end if

But I am getting this error when I commit or execute the pre-commit. Even when "Some App" is not running.

.git/hooks/pre-commit:50:106: execution error: An error of type -10810 has occurred. (-10810)

Permissions on the file are

-rwxr-xr-x@ 1 toddgeist  staff   263 Dec  7 07:33 pre-commit

2 Answers 2


You don't say what problem you're running into, so let me guess.

If you're having trouble with how to phrase the "-- show a message and exit with non zero status" part, use the error command:

#!/usr/bin/env osascript

tell application "System Events"
    set apps to the name of every process whose background only is false
end tell

if "Some Application" is in apps then
    error "Some Application is running" number 5
end if

The number (5 in the example) doesn't matter; osascript will exit with status 1 no matter what number you choose. You don't have control over the formatting of the message, but the non-zero exit status will block the commit.

If you're having trouble getting the pre-commit hook to even run, remember to save it as .git/hooks/pre-commit and make it executable.

(update) if you get the -10810 error try doing it with out System Events. Like this

#!/usr/bin/env osascript

set someApp to "Some App"
set appIsRunning to false
if application someApp is running then
    set appIsRunning to true
end if
if appIsRunning then
    error "Can't commit. Please quit Some App" number 5
end if
  • yes, that was the problem.
    – toddgeist
    Dec 7, 2014 at 15:21
  • still getting an error. Updating the question
    – toddgeist
    Dec 7, 2014 at 15:46
  • Error -10810 is a catch-all Launch Services error, meaning some app could not be launched but for an unknown reason. The problem is not in the AppleScript itself (because OSA Script would give a more specific error) although the code you posted has a syntax error (unmatched quotes).
    – ganbustein
    Dec 7, 2014 at 19:53
  • sadly the syntax error was just a copy and paste typo. Corrected
    – toddgeist
    Dec 8, 2014 at 17:56
  • if I take out the call to System Events it works. so perhaps System Events can't be called in this way
    – toddgeist
    Dec 8, 2014 at 18:00

If your osascript (above) works you can launch it via a shell script. Turn the osascript into an app with the script editor. Then this shell script could be your git pre-commit hook. Something like:

/usr/bin/osascript $HOME/bin/YOUR_OSASCRIPT.app 2>/dev/null

I use this technique to launch scripts via crontab so it should work in your situation.

You must log in to answer this question.

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