CGI + appscript newbie question/problem

Andres Francisco Rojas afrojas at gmail.com
Sun May 27 20:00:06 EDT 2007


Hey everyone. So I'm more or less new to Python, just wanted to say that
right up front so please excuse any silly questions.

Generally what I'm trying to do is control a Mac OS X application through a
website via Python and appscript. I have successfully got Apache running and
configured to run Python scripts, basic modules like os and cgi work and I
can do silly form processing and stuff like that, so I know Python itself is
good to go, along with the web server. I can execute AppleScript commands,
and control applications, successfully using appscript when using Python via
Terminal (and following along with the examples), but when I try to import
appscript into the script run as cgi I get an 500 Internal Server Error. I
know it's the import call because I can comment it out and the script runs,
but I can't do any AppleScripting (obviously).

Is there a limitation to running appscript when in cgi on Apache? Is there
an Apache setting I'm missing? Everything is local, by the way, running off
the machine I'm writing this message on. Below is the code that Apache runs:

#!/usr/bin/python

import cgi
from appscript import *

print "Content-Type: text/html\n\n"

# Define function to generate HTML form.
def generate_form():
    print "<HTML>\n"
    print "<HEAD>\n"
    print "\t<TITLE>Info Form</TITLE>\n"
    print "</HEAD>\n"
    print "<BODY>\n"
    print "\t<FORM METHOD = post ACTION = \"1.cgi\">\n"
    print "\t<INPUT TYPE = hidden NAME = \"action\" VALUE = \"launch\">\n"
    print "\t<INPUT TYPE = submit VALUE = \"LAUNCH\">\n"
    print "</BODY>\n"
    print "</HTML>\n"

# Define main function.
def main():
    form = cgi.FieldStorage()
    if (form.has_key("action")):
             if (form["action"].value == "launch"):
                print "COUNTDOWN!"
                texteditGUI = app('System Events').processes['TextEdit']
                app('TextEdit').activate()
                mref = texteditGUI.menu_bars[1].menus
                mref['File'].menu_items['New'].click()
                mref['Edit'].menu_items['Paste'].click()
                mref['Window'].menu_items['Zoom Window'].click()
    else:
             generate_form()

# Call main function.
main()



I tried using both 'from appscript import *' and 'import appscript' and it
doesn't make a difference. 'from appscript import *' is the way it
successfully works when using the command line interpreter.

Thanks for any help on this!

-Andrés Rojas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070527/80c06043/attachment.html>


More information about the Python-list mailing list