3 * This is a simple module to allow the
4 * user to compile and execute an applescript
5 * which is passed in as a text item.
7 * Sean Hummel <seanh@prognet.com>
11 * Jay Painter <jpaint@serv.net> <jpaint@gimp.org> <jpaint@real.com>
16 #include "ScriptRunner.h"
17 #include <AppleEvents.h>
22 * Boiler plate generated from "genmodule.py"
24 static PyObject
*ErrorObject
;
25 static char OSAm_DoCommand__doc__
[] = "";
30 OSAm_RunCompiledScript (self
, args
)
34 char *commandStr
= NULL
;
40 temp
.dataHandle
= NULL
;
42 if (!PyArg_ParseTuple (args
, "s", &commandStr
))
45 myErr
= ExecuteScriptFile (commandStr
, NULL
, &temp
);
47 if (temp
.dataHandle
!= NULL
&& temp
.descriptorType
== 'TEXT')
53 HLock (temp
.dataHandle
);
55 dataSize
= GetHandleSize (temp
.dataHandle
);
59 PyObject
*result
= PyString_FromStringAndSize ((*temp
.dataHandle
),
62 AEDisposeDesc (&temp
);
66 printf ("OSAm.error Out of memory.\n");
77 PyErr_Mac (ErrorObject
, myErr
);
90 OSAm_CompileAndSave (self
, args
)
94 char *commandStr
= NULL
;
100 temp
.dataHandle
= NULL
;
102 if (!PyArg_ParseTuple (args
, "ss", &commandStr
, &outpath
))
105 myErr
= CompileAndSave (commandStr
, outpath
, NULL
, &temp
);
108 if (temp
.dataHandle
!= NULL
&& temp
.descriptorType
== 'TEXT')
114 HLock (temp
.dataHandle
);
116 dataSize
= GetHandleSize (temp
.dataHandle
);
120 PyObject
*result
= PyString_FromStringAndSize ((*temp
.dataHandle
),
123 AEDisposeDesc (&temp
);
127 printf ("OSAm.error Out of memory.\n");
140 PyErr_Mac (ErrorObject
, myErr
);
152 OSAm_CompileAndExecute (self
, args
)
161 temp
.dataHandle
= NULL
;
163 if (!PyArg_ParseTuple (args
, "s", &commandStr
))
166 myErr
= CompileAndExecute (commandStr
, &temp
, NULL
);
168 if (temp
.dataHandle
!= NULL
&& temp
.descriptorType
== 'TEXT')
174 HLock (temp
.dataHandle
);
176 dataSize
= GetHandleSize (temp
.dataHandle
);
180 PyObject
*result
= PyString_FromStringAndSize ((*temp
.dataHandle
),
183 AEDisposeDesc (&temp
);
187 printf ("OSAm.error Out of memory.\n");
199 PyErr_Mac (ErrorObject
, myErr
);
211 * List of methods defined in the module
213 static struct PyMethodDef OSAm_methods
[] =
215 {"CompileAndExecute",
216 (PyCFunction
) OSAm_CompileAndExecute
,
218 OSAm_DoCommand__doc__
},
221 (PyCFunction
) OSAm_CompileAndSave
,
223 OSAm_DoCommand__doc__
},
225 {"RunCompiledScript",
226 (PyCFunction
) OSAm_RunCompiledScript
,
228 OSAm_DoCommand__doc__
},
230 {NULL
, (PyCFunction
) NULL
, 0, NULL
}
235 static char OSAm_module_documentation
[] = "";
239 * PYTHON Module Initalization
246 /* Create the module and add the functions */
247 m
= Py_InitModule4 ("OSAm",
249 OSAm_module_documentation
,
250 (PyObject
*) NULL
, PYTHON_API_VERSION
);
253 /* Add some symbolic constants to the module */
254 d
= PyModule_GetDict (m
);
255 ErrorObject
= PyString_FromString ("OSAm.error");
256 PyDict_SetItemString (d
, "error", ErrorObject
);
259 /* Check for errors */
260 if (PyErr_Occurred ())
261 Py_FatalError ("can't initialize module OSAm");