home *** CD-ROM | disk | FTP | other *** search
- /*
- * ASTcl -- DoAppleScript package for MacTcl 7.5.1
- * This code adds the command "DoAppleScript <script>" to MacTcl.
- *
- * ASTcl.c -- package initialization and command handler
- * Written on 960927.
- *
- * Copyright (c) 1996 by Theodore C. Belding
- * University of Michigan Program for the Study of Complex Systems
- * <mailto:Ted.Belding@umich.edu>
- * <http://www-personal.engin.umich.edu>
- *
- * This code is freeware.
- */
-
- #include <string.h>
- #include <stdlib.h>
-
- #include "tcl.h"
- #include "ASTcl.h"
- #include "ASTclUtils.h"
-
- /* maximum length of result string */
- #define kMaxResultLen 256
-
- static int DoAppleScriptCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
-
- /*
- * Package initialization
- */
-
- int ASTcl_Init(Tcl_Interp *interp) {
- /* add DoAppleScript command into Tcl interpreter */
- Tcl_CreateCommand(interp, "DoAppleScript", DoAppleScriptCmd, NULL, NULL);
-
- /* initialize AppleScript OSA component */
- if (OSAScriptInit()) {
- return TCL_ERROR;
- }
- else
- return TCL_OK;
- }
-
-
- /*
- * DoAppleScript command handler
- */
-
- static int DoAppleScriptCmd(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
- {
- char* script;
- char* result = calloc(kMaxResultLen, sizeof(char));
-
- /* usage: DoAppleScript <script> */
- if (argc != 2) {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- " script\"", (char *) NULL);
- return TCL_ERROR;
- }
- script = argv[1];
-
- /* compile and execute script */
- if (ProcessScript(script, result)) {
- /* get error result */
- Tcl_SetResult(interp, result, TCL_DYNAMIC);
- return TCL_ERROR;
- }
- else {
- /* set result */
- Tcl_SetResult(interp, result, TCL_DYNAMIC);
- return TCL_OK;
- }
- }
-
-