josh273

Q: AppleScript Error 10810

How do I fix the following?

root# /usr/bin/osascript /Users/me/Documents/balance_volume.scpt

/Users/josh/Documents/balance_volume2.scpt: execution error: An error of type -10810 has occurred. (-10810)

 

My iMac volume balance constantly sets itself to a new random position so I created the following AppleScript:

 

tell application "System Preferences"

    activate

    set current pane to pane "com.apple.preference.sound"

    reveal (first anchor of current pane whose name is "output")

end tell

 

tell application "System Events"

    launch

    tell process "System Preferences" to tell slider 1 of group 1 of tab group 1 of window 1 to set value to 0.5 --center balance

    -- tell process "System Preferences" to set value of slider 1 of group 1 of window "Sound" to 0 --maximize volume

    quit application "System Preferences"

end tell

 

The script works everytime when run from AppleScript Editor.  But if I save and try to run from the command line, it runs sometimes, but not others.  Eventually I want to put in crontab:

* 20 * * * /usr/bin/osascript /Users/me/Documents/balance_volume.scpt

 

I've read about "compiling" or saving as an application the scpt file but not sure how to do this.

 

Thank you.

Posted on Feb 21, 2013 5:21 PM

Close

Q: AppleScript Error 10810

  • All replies
  • Helpful answers

  • by Camelot,

    Camelot Camelot Feb 22, 2013 12:11 AM in response to josh273
    Level 8 (47,285 points)
    Mac OS X
    Feb 22, 2013 12:11 AM in response to josh273

    Do you have any idea of the difference conditions under which is does/does not run?

     

    For example, your script is doomed to failure if no user is logged in - you can't launch System Preferences.app without someone logged in, and cron isn't going to check.

     

    This script would be better executed via a LaunchAgent - LauchAgents are active only when a user is logged in, so that takes care of the issue related to launching applications. It's also the preferred model for periodic tasks rather than cron.

     

    Personally, though, I'd take a look for what's causing the balance to change in the first place. That's not a normal situation, so I'd rather look for the cause rather than hack together a 'fix'.

  • by josh273,

    josh273 josh273 Feb 22, 2013 5:04 AM in response to Camelot
    Level 1 (0 points)
    Feb 22, 2013 5:04 AM in response to Camelot

    Thanks Camelot.  However, I have searched many hours for a resolution to the balance issue and it seems to be well known and no fix.  Thus, my aggrivation and pursuit of this hack job I really don't want.

     

    Cron aside, and if the user is logged in or not (will explore these), the script runs fine in AppleScript Editor.  It does not run from the command line.  What is the best way to run a script from the command line?


    Thank you.

  • by Pierre L.,

    Pierre L. Pierre L. Feb 22, 2013 6:29 AM in response to josh273
    Level 5 (4,484 points)
    Feb 22, 2013 6:29 AM in response to josh273

    After saving the script to the Desktop, under the name "Test.scpt", the following seems to work:

    Capture d’écran 2013-02-22 à 09.29.11.png

  • by josh273,

    josh273 josh273 Feb 22, 2013 6:51 AM in response to Pierre L.
    Level 1 (0 points)
    Feb 22, 2013 6:51 AM in response to Pierre L.

    Pierre,  that is excatly what I'm doing when I get the error. =(

  • by Pierre L.,

    Pierre L. Pierre L. Feb 22, 2013 7:16 AM in response to josh273
    Level 5 (4,484 points)
    Feb 22, 2013 7:16 AM in response to josh273

    Then I would try a minimalist version of the script. Who knows?

     

    tell application "System Preferences"

        reveal (anchor 1 of pane "com.apple.preference.sound" whose name is "output")

        tell application "System Events" to tell process "System Preferences" to tell slider 1 of group 1 of tab group 1 of window 1 to set value to 0.5 --center balance

        quit

    end tell

  • by josh273,

    josh273 josh273 Feb 22, 2013 7:33 AM in response to Pierre L.
    Level 1 (0 points)
    Feb 22, 2013 7:33 AM in response to Pierre L.

    That worked from AppleScript, then from command line once.  After that, same error.  It seems if I save the original script or this new one, they run once only.  Then they stop.

  • by Pierre L.,

    Pierre L. Pierre L. Feb 22, 2013 7:43 AM in response to josh273
    Level 5 (4,484 points)
    Feb 22, 2013 7:43 AM in response to josh273

    I fear I can be of no help. Maybe you might have a look at this Web page.