[2] | 1 | /*
|
---|
[391] | 2 | ** An interface to the application scripting related functions of the OSA API.
|
---|
[2] | 3 | **
|
---|
[391] | 4 | ** GetAppTerminology - given an FSSpec/posix path to an application,
|
---|
| 5 | ** returns its aevt (scripting terminology) resource(s)
|
---|
| 6 | **
|
---|
| 7 | ** GetSysTerminology - returns the AppleScript language component's
|
---|
| 8 | ** aeut (scripting terminology) resource
|
---|
| 9 | **
|
---|
| 10 | ** Written by Donovan Preston and slightly modified by Jack and HAS.
|
---|
[2] | 11 | */
|
---|
| 12 | #include "Python.h"
|
---|
| 13 | #include "pymactoolbox.h"
|
---|
| 14 |
|
---|
| 15 | #include <Carbon/Carbon.h>
|
---|
| 16 |
|
---|
| 17 | #ifndef __LP64__
|
---|
| 18 | static PyObject *
|
---|
| 19 | PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
|
---|
| 20 | {
|
---|
[391] | 21 | AEDesc theDesc = {0,0};
|
---|
| 22 | FSSpec fss;
|
---|
| 23 | ComponentInstance defaultComponent = NULL;
|
---|
| 24 | SInt16 defaultTerminology = 0;
|
---|
| 25 | Boolean didLaunch = 0;
|
---|
| 26 | OSAError err;
|
---|
| 27 | long modeFlags = 0;
|
---|
| 28 |
|
---|
| 29 | if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
|
---|
| 30 | return NULL;
|
---|
| 31 |
|
---|
| 32 | /*
|
---|
| 33 | ** Note that we have to use the AppleScript component here. Who knows why
|
---|
| 34 | ** OSAGetAppTerminology should require a scripting component in the
|
---|
| 35 | ** first place, but it does. Note: doesn't work with the generic scripting
|
---|
| 36 | ** component, which is unfortunate as the AS component is currently very
|
---|
| 37 | ** slow (~1 sec?) to load, but we just have to live with this.
|
---|
| 38 | */
|
---|
| 39 | defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
|
---|
| 40 | err = GetComponentInstanceError (defaultComponent);
|
---|
| 41 | if (err) return PyMac_Error(err);
|
---|
| 42 | err = OSAGetAppTerminology (
|
---|
| 43 | defaultComponent,
|
---|
| 44 | kOSAModeNull,
|
---|
| 45 | &fss,
|
---|
| 46 | defaultTerminology,
|
---|
| 47 | &didLaunch,
|
---|
| 48 | &theDesc
|
---|
| 49 | );
|
---|
| 50 | if (err) return PyMac_Error(err);
|
---|
| 51 | return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
|
---|
[2] | 52 | }
|
---|
| 53 |
|
---|
| 54 | static PyObject *
|
---|
| 55 | PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
|
---|
| 56 | {
|
---|
[391] | 57 | AEDesc theDesc = {0,0};
|
---|
| 58 | ComponentInstance defaultComponent = NULL;
|
---|
| 59 | SInt16 defaultTerminology = 0;
|
---|
| 60 | OSAError err;
|
---|
| 61 |
|
---|
| 62 | /* Accept any args for sake of backwards compatibility, then ignore them. */
|
---|
| 63 |
|
---|
| 64 | defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
|
---|
| 65 | err = GetComponentInstanceError (defaultComponent);
|
---|
| 66 | if (err) return PyMac_Error(err);
|
---|
| 67 | err = OSAGetSysTerminology (
|
---|
| 68 | defaultComponent,
|
---|
| 69 | kOSAModeNull,
|
---|
| 70 | defaultTerminology,
|
---|
| 71 | &theDesc
|
---|
| 72 | );
|
---|
| 73 | if (err) return PyMac_Error(err);
|
---|
| 74 | return Py_BuildValue("O&", AEDesc_New, &theDesc);
|
---|
[2] | 75 | }
|
---|
| 76 | #endif /* !__LP64__ */
|
---|
| 77 |
|
---|
[391] | 78 | /*
|
---|
[2] | 79 | * List of methods defined in the module
|
---|
| 80 | */
|
---|
| 81 | static struct PyMethodDef OSATerminology_methods[] =
|
---|
| 82 | {
|
---|
| 83 | #ifndef __LP64__
|
---|
[391] | 84 | {"GetAppTerminology",
|
---|
| 85 | (PyCFunction) PyOSA_GetAppTerminology,
|
---|
| 86 | METH_VARARGS,
|
---|
| 87 | "Get an application's terminology. GetAppTerminology(path) --> AEDesc"},
|
---|
| 88 | {"GetSysTerminology",
|
---|
| 89 | (PyCFunction) PyOSA_GetSysTerminology,
|
---|
| 90 | METH_VARARGS,
|
---|
| 91 | "Get the AppleScript language's terminology. GetSysTerminology() --> AEDesc"},
|
---|
[2] | 92 | #endif /* !__LP64__ */
|
---|
[391] | 93 | {NULL, (PyCFunction) NULL, 0, NULL}
|
---|
[2] | 94 | };
|
---|
| 95 |
|
---|
| 96 | void
|
---|
| 97 | initOSATerminology(void)
|
---|
| 98 | {
|
---|
[391] | 99 | if (PyErr_WarnPy3k("In 3.x, the OSATerminology module is removed.", 1) < 0)
|
---|
| 100 | return;
|
---|
| 101 | Py_InitModule("OSATerminology", OSATerminology_methods);
|
---|
[2] | 102 | }
|
---|