[Pythonmac-SIG] findertools Error

Ned Deily nad at acm.org
Tue Sep 16 07:42:40 CEST 2008


In article 
<84bdef3c0809151646u1d49a912nab006a0c00db2e3e at mail.gmail.com>,
 "Rajanikanth Jammalamadaka" <rajanikanth at gmail.com> wrote:

> Could somebody please tell me why I get this error?
> 
> >>> import findertools
> >>> findertools.sleep()
[...]

The simple answer is: don't use findertools, or most other MacPython 
modules for that matter.  They were written for classic MacOS, aren't 
really supported anymore under OS X, and are being removed in future 
versions of Python.

You're on the right track by using appscript.

> >>> from appscript import *
> >>> app(u'Finder').sleep()
> 
> Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     app(u'Finder').sleep()
>   File 
>   "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packag
>   es/appscript-0.18.1-py2.5-macosx-10.5-i386.egg/appscript/reference.py",
> line 439, in __call__
>     raise CommandError(self, (args, kargs), e)
> CommandError: CommandError -1708: Application could not handle this command.
> 	Failed command: app(u'/System/Library/CoreServices/Finder.app').sleep()
> >>> app(u'Finder').sleep()
> 
> Traceback (most recent call last):
>   File "<pyshell#4>", line 1, in <module>
>     app(u'Finder').sleep()
>   File 
>   "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packag
>   es/appscript-0.18.1-py2.5-macosx-10.5-i386.egg/appscript/reference.py",
> line 439, in __call__
>     raise CommandError(self, (args, kargs), e)
> CommandError: CommandError -1708: Application could not handle this command.
> 	Failed command: app(u'/System/Library/CoreServices/Finder.app').sleep()

The problem here is that "sleep" and various other commands. which were 
a part of the Finder in classic MacOS, are now - under the covers - 
implemented by other services in OS X.  In particular, 'sleep' and other 
power events are scripted through the "System Events" agent.

>>> from appscript import *
>>> app('System Events').sleep()

You can browse its terminology using, for example, appscript's built-in 
help introspection or Apple's Script Editor.

> Also, what would be the best way to mount a .dmg file using appscript?

One simple way is to just pass the path of the .dmg file to System 
Event's open:

>>> app('System Events').open('/Users/nad/blah.dmg')

If that's too simple-minded, you could wrap a shell call to hdiutil(1).

-- 
 Ned Deily,
 nad at acm.org



More information about the Pythonmac-SIG mailing list