I use a function whose sole purpose is to return a reference to System Events to avoid this problem:
import appscript as ap def getSystemEvents(): try: # ask System Events for processes to see if it's there throwaway = ap.app('/System Events').processes() # would calling run() be better? result = ap.app('/System Events') except: # open up, Mr System Events ap.app('/Finder').startup_disk.items[':System:Library:CoreServices:System Events'].open() result = ap.app('/System Events') On Sat, Mar 27, 2010 at 1:35 PM, Noah Coccaro <n...@coccaro.com> wrote: > I have a long running server that uses appscript to send keystroke commands > to System Events. > It seems that System Events does not run constantly, or frequently dies. > Quite often, appscript seems to be in a state where it incorrectly thinks > System Events is running, and still sends commands to it, resulting in > failures. > > Is there a workaround for this? A way to tell appscript that an app > definitly is not running, or clear some cache maybe that is lingering? I > notice if I start a different python instance, and send commands to System > Events, it correctly starts it up. > > Here is a error dump from running essentially app('System Events').run() > when it thought it was already running -- the same happens with launch, or > any other command -- appscript can't get the terminology for System Events > because it isn't running: > > File "./avjamasserver.py", line 102, in do_POST > result = self.CallFunction(request, av.activity) > File "./avjamasserver.py", line 74, in CallFunction > return function(*function_args) > File "/Users/noah/Software/RS232/avcontrol.py", line 300, in AudioMode > SafeStart(sys_events) > File "/Users/noah/Software/RS232/avcontrol.py", line 20, in SafeStart > app_instance.run() > File "build/bdist.macosx-10.5-i386/egg/appscript/reference.py", line 578, > in __getattr__ > selectortype, code = self.AS_appdata.referencebyname()[name] > File "build/bdist.macosx-10.5-i386/egg/appscript/reference.py", line 260, > in referencebyname > self.connect() > File "build/bdist.macosx-10.5-i386/egg/appscript/reference.py", line 229, > in connect > self._terms = terminology.tablesforapp(t) > File "build/bdist.macosx-10.5-i386/egg/appscript/terminology.py", line > 171, in tablesforapp > _terminologycache[aemapp.AEM_identity] = > tablesforaetes(aetesforapp(aemapp)) > File "build/bdist.macosx-10.5-i386/egg/appscript/terminology.py", line > 143, in aetesforapp > raise RuntimeError("Can't get terminology for application (%r): %s" % > (aemapp, e)) > RuntimeError: Can't get terminology for application > (aem.Application(u'/System/Library/CoreServices/System Events.app')): > Command failed: Application isn't runnin > g. (-600) > > > > _______________________________________________ > Pythonmac-SIG maillist - Pythonmac-SIG@python.org > http://mail.python.org/mailman/listinfo/pythonmac-sig > unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG > >
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig unsubscribe: http://mail.python.org/mailman/options/Pythonmac-SIG