[Pythonmac-SIG] pythonw and python with applescript

Kevin Walzer sw at wordtech-software.com
Tue Dec 13 19:18:48 CET 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Zhi Peng wrote:
> Hi! All 
> 
> I posted a few items in a few days. I think the first
> problem I had is that it can not import python module
> when I used "from appscrpt import *" inside modue
> because appscript need pythonw instead of python. Here
> is the error message: 
> 
> ========================================================
> 
> zhi-pengs-power-mac-g5:~/Documents/projects/c-code/pyToDLL/test1
> zpeng$ python
> Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)]
> on darwin
> Type "help", "copyright", "credits" or "license" for
> more information.
>>>> import StringModule
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "StringModule.py", line 4, in ?
>     from appscript import *
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/appscript/__init__.py",
> line 14, in ?
>     from specifier import app, CommandError
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/appscript/specifier.py",
> line 9, in ?
>     import aem
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/aem/__init__.py",
> line 25, in ?
>     from send import *
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/aem/send/__init__.py",
> line 105, in ?
>     raise RuntimeError, "Can't send Apple events: no
> access to Window Manager. (aem-based scripts must be
> run within a GUI process; e.g. use 'pythonw', not
> 'python', if running script in shell)"
> RuntimeError: Can't send Apple events: no access to
> Window Manager. (aem-based scripts must be run within
> a GUI process; e.g. use 'pythonw', not 'python', if
> running script in shell)
> 
> ====================================================
> 
> Does anyone have any ideal on solving the probelm.
> Thanks in advance. 
> 
> It seems PyImport_ImportModule also use python instead
> of pythonw. 
> 
> 
> Regards 
> 
> Zhi 
> 

On OS X, scripts that have a GUI must be launched with pythonw, not
python. If your script uses Tkinter or wxPython, for instance, you would
(from the terminal) launch it by saying "pythonw foo.py." Running it
with "python foo.py" will produce errors simlilar to the ones you are
reporting.

Not sure if appscript modules can be run interactively with the Python
interpreter/shell--has can chime in here.

- --
Cheers,

Kevin Walzer, PhD
WordTech Software - "Tame the Terminal"
http://www.wordtech-software.com
sw at wordtech-software.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFDnxCHJmdQs+6YVcoRAkPuAJ9C1Ulazs2NQtrNFfFqxnrPGbj3PwCWMez3
HkUHJT3LnISQoDU/QL0fzg==
=BLI9
-----END PGP SIGNATURE-----


More information about the Pythonmac-SIG mailing list