On Sun, May 27, 2007 at 05:04:25PM -0700, Andres Francisco Rojas wrote: > but when I try to import appscript into the script run as cgi I get > an 500 Internal Server Error.
Typically you should look in the Web server logs (/var/log/httpd/error_log) in that case to see the details of the error, which are not returned in the browser to preserve security. You can also do: import cgitb; cgitb.enable() at the beginning of your script, so you get a nice HTML traceback if you get a Python exception. The thing is, I tried your script (after cleaning it up slightly) and I don't get a 500 error or the expected result, I simply get the following in the error log: "INIT_Processeses(), could not establish the default connection to the WindowServer." Since you're using /usr/bin/python and assuming you're using 10.4.x, that should be the system Python 2.3.5. What version of appscript are you using? (You can print it with 'import appscript; appscript.__version__'). > # Define function to generate HTML form. > def generate_form(): > print "<HTML>\n" 'print' already includes newlines, you don't need to use them. Not that string printing is a recommended templating mechanism, but if you do need to do it, you might try one of Python's other quoting styles; you can always use single quotes so you don't need to escape things, or triple quotes for multiline strings. For example, instead of: print "\t<FORM METHOD=post ACTION=\"1.cgi\">\n" print "\t<INPUT TYPE=hidden NAME=\"action\" VALUE=\"launch\">\n" use: print '\t<form method="post" action="1.cgi"' print '\t<input type="hidden" name="action" value="launch">' So, as other people mentioned, you don't have access to control local apps as the Web server user. This is a good thing for security. However, you may be able to use remote Apple Events to do it. I couldn't figure out a way to get a remote application to launch without using the Finder. Appscript fails because it can't get the app's terminology; with terms=False on a non-running TextEdit, I get "AppData instance has no attribute 'path'". This is really hacky, but it works sometimes; other times I get a timeout during terminology retrieval. This may just be my slow old machine. app(url='eppc://user:[EMAIL PROTECTED]/Finder').startup_disk.files['Applications:TextEdit.app'].open() texteditGUI = app(url='eppc://user:[EMAIL PROTECTED]/System%20Events').processes['TextEdit'] app(url='eppc://user:[EMAIL PROTECTED]/TextEdit', path='/Applications/TextEdit.app').activate() mref = texteditGUI.menu_bars[1].menus mref['File'].menu_items['New'].click() mref['Edit'].menu_items['Paste'].click() mref['Window'].menu_items['Zoom'].click() Replace user:password with your username and password, above. > mref['Window'].menu_items['Zoom Window'].click() On my 10.4.9 machine this menu item is "Zoom", not "Zoom Window". -- Nicholas Riley <[EMAIL PROTECTED]> | <http://www.uiuc.edu/ph/www/njriley> _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig