The Infamous OS X execution error: An error of type -10810 has occurred. (-10810)

This error seems to appear often when I am using  osascript  for automating things.  This error is a bit of a mystery as hundreds of users will say.  In addition, it is not even listed in the MacErrors.h  file found at:

/System/Library/Frameworks//CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/MacErrors.h

After a lot of searching, I found some possible reasons why this error occurs:

Since I mostly deal with scripting and automation, this post will be more about that and not so much about the Finder not being able to open because of this error.

There Is Not A GUI, But One Is Required

This error sometimes appears when running a script that requires a GUI, but the script is being run as root.  The solution here is to get the current user and substitute as them.

First, you need to get the current user and store that value in a variable, which can be done a number of ways:

currentUser=$(stat -f "%Su" /dev/console)
# Alternate ways to get the currently logged in user
currentUser=$(who | grep console | awk '{print $1}')
currentUser=$(logname)
currentUser=$(ls -l /dev/console | cut -d " " -f4)
currentUser=$(printf "get State:/Users/ConsoleUser\nd.show" | scutil | awk '/kCGSSessionUserNameKey/ {print $3}')

Then you can run the script under that user’s context:

su "$currentUser" -c "your commands here"

When running as root, another method is to use bsexec .  I found this method useful with terminal-notifier.

loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
loggedInPID=$( ps -axj | awk "/^$loggedInUser/ && /Dock.app/ {print \$2;exit}" )
/bin/launchctl bsexec "${loggedInPID}" sudo -iu "${loggedInUser}" "some commands here"

Access To Assistive Devices Is Not Enabled

I saw this a few times when trying to script a GUI login, but was resolved with enabling access to assistive devices.

On OS X 10.8 and Earlier…

Just run this command and reboot the computer:

sudo touch /private/var/db/.AccessibilityAPIEnabled

On OS X 10.9 and Up…

Use something like tccutil.py to add a specific app to the Accessibility database from the command line.

The Process Table Is Full

You can find out how many processes are allowed to run using either of these commands:

sysctl kern.maxproc
ulimit -a

I never tried this, but you could try setting the max allowed processes to a higher number.  I’m not certain what would happen if it gets set too high:

sysctl -w kern.maxproc=1000

Another good troubleshooting tip is this command, which will count all processes so you can see if you are close to the limit.

ps -xa | wc -l

LaunchServices Failure

Yet another cause of this error has to do with LaunchServices, but the best solution would be to reboot, or investigate using the process-table method above.

Help With This Error

If you have run into this error elsewhere or have been able to solve it, let me know in the ocmments.

7 Replies to “The Infamous OS X execution error: An error of type -10810 has occurred. (-10810)”

  1. Hi! i have the same problem.. i think.. all my applescript app (saved as application) doesn’t start on Yosemite. They start only if when i save the .app file i flag the “show startup dialog”..

    is this the same problem that you have?

    Thanks

      1. i have created a simple applescript .app file that say “hello”. If i launch it with command line “open /Application/hello.app” it open.. if i double click on the app.. it open and close immediatly…

  2. Just came across this page while trying to work out why my startup script was failing with the -10810 error. Running the script manually indicated that the failure occurred as it executed the line

    tell application ProgramName to activate

    and the variable ProgramName was set to ‘DevonThink Pro’.

    Further investigation demonstrated that the problem was with the application. If I tried to launch it from the Dock the active program indicator would flick on and then off again, so fast that it was hardly observable. If I tried to launch it from the Applications folder, the animation would run as normal, but then the focus would remain with the Finder and the program wouldn’t launch.

    Reinstalling the application sorted the issue – no more 10810 errors.

Leave a Reply