summaryrefslogtreecommitdiff
path: root/Mac/PythonLauncher
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2008-05-02 21:42:35 +0000
committerRonald Oussoren <ronaldoussoren@mac.com>2008-05-02 21:42:35 +0000
commit54e7b3fa7ba77819484fb379ec6aa56234d99e4d (patch)
treed3d993626f04c43bc0aea38bf092f806c1b56fe4 /Mac/PythonLauncher
parentd87005924519a3fa81a399daa65612e9058dcf0f (diff)
downloadcpython-54e7b3fa7ba77819484fb379ec6aa56234d99e4d.tar.gz
Fix for #1905: PythonLauncher not working correctly on OSX 10.5/Leopard
This fixes both Python Launchar and the terminalcommand module.
Diffstat (limited to 'Mac/PythonLauncher')
-rwxr-xr-xMac/PythonLauncher/MyDocument.m4
-rw-r--r--Mac/PythonLauncher/doscript.m141
2 files changed, 43 insertions, 102 deletions
diff --git a/Mac/PythonLauncher/MyDocument.m b/Mac/PythonLauncher/MyDocument.m
index 5acc2dcc90..86112c4b15 100755
--- a/Mac/PythonLauncher/MyDocument.m
+++ b/Mac/PythonLauncher/MyDocument.m
@@ -121,8 +121,8 @@
return YES;
} else {
[self run];
- [self close];
- return NO;
+ [self performSelector:@selector(close) withObject:nil afterDelay:0.0];
+ return YES;
}
}
diff --git a/Mac/PythonLauncher/doscript.m b/Mac/PythonLauncher/doscript.m
index 3e4e22393c..024b883f19 100644
--- a/Mac/PythonLauncher/doscript.m
+++ b/Mac/PythonLauncher/doscript.m
@@ -11,108 +11,49 @@
#import <ApplicationServices/ApplicationServices.h>
#import "doscript.h"
-/* I assume I could pick these up from somewhere, but where... */
-#define CREATOR 'trmx'
-
-#define ACTIVATE_CMD 'misc'
-#define ACTIVATE_SUITE 'actv'
-
-#define DOSCRIPT_CMD 'dosc'
-#define DOSCRIPT_SUITE 'core'
-#define WITHCOMMAND 'cmnd'
-
-/* ... and there's probably also a better way to do this... */
-#define START_TERMINAL "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal &"
-
extern int
doscript(const char *command)
{
- OSErr err;
- AppleEvent theAEvent, theReply;
- AEAddressDesc terminalAddress;
- AEDesc commandDesc;
- OSType terminalCreator = CREATOR;
-
- /* set up locals */
- AECreateDesc(typeNull, NULL, 0, &theAEvent);
- AECreateDesc(typeNull, NULL, 0, &terminalAddress);
- AECreateDesc(typeNull, NULL, 0, &theReply);
- AECreateDesc(typeNull, NULL, 0, &commandDesc);
-
- /* create the "activate" event for Terminal */
- err = AECreateDesc(typeApplSignature, (Ptr) &terminalCreator,
- sizeof(terminalCreator), &terminalAddress);
- if (err != noErr) {
- NSLog(@"doscript: AECreateDesc: error %d\n", err);
- goto bail;
- }
- err = AECreateAppleEvent(ACTIVATE_SUITE, ACTIVATE_CMD,
- &terminalAddress, kAutoGenerateReturnID,
- kAnyTransactionID, &theAEvent);
-
- if (err != noErr) {
- NSLog(@"doscript: AECreateAppleEvent(activate): error %d\n", err);
- goto bail;
- }
- /* send the event */
- err = AESend(&theAEvent, &theReply, kAEWaitReply,
- kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
- if ( err == -600 ) {
- int count=10;
- /* If it failed with "no such process" try to start Terminal */
- err = system(START_TERMINAL);
- if ( err ) {
- NSLog(@"doscript: system(): %s\n", strerror(errno));
- goto bail;
- }
- do {
- sleep(1);
- /* send the event again */
- err = AESend(&theAEvent, &theReply, kAEWaitReply,
- kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
- } while (err == -600 && --count > 0);
- if ( err == -600 )
- NSLog(@"doscript: Could not activate Terminal\n");
- }
- if (err != noErr) {
- NSLog(@"doscript: AESend(activate): error %d\n", err);
- goto bail;
- }
-
- /* create the "doscript with command" event for Terminal */
- err = AECreateAppleEvent(DOSCRIPT_SUITE, DOSCRIPT_CMD,
- &terminalAddress, kAutoGenerateReturnID,
- kAnyTransactionID, &theAEvent);
- if (err != noErr) {
- NSLog(@"doscript: AECreateAppleEvent(doscript): error %d\n", err);
- goto bail;
- }
-
- /* add the command to the apple event */
- err = AECreateDesc(typeChar, command, strlen(command), &commandDesc);
- if (err != noErr) {
- NSLog(@"doscript: AECreateDesc(command): error %d\n", err);
- goto bail;
- }
- err = AEPutParamDesc(&theAEvent, WITHCOMMAND, &commandDesc);
- if (err != noErr) {
- NSLog(@"doscript: AEPutParamDesc: error %d\n", err);
- goto bail;
- }
+ char *bundleID = "com.apple.Terminal";
+ AppleEvent evt, res;
+ AEDesc desc;
+ OSStatus err;
+
+ [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Terminal.app/"];
+
+ // Build event
+ err = AEBuildAppleEvent(kAECoreSuite, kAEDoScript,
+ typeApplicationBundleID,
+ bundleID, strlen(bundleID),
+ kAutoGenerateReturnID,
+ kAnyTransactionID,
+ &evt, NULL,
+ "'----':utf8(@)", strlen(command),
+ command);
+ if (err) {
+ NSLog(@"AEBuildAppleEvent failed: %d\n", err);
+ return err;
+ }
+
+ // Send event and check for any Apple Event Manager errors
+ err = AESendMessage(&evt, &res, kAEWaitReply, kAEDefaultTimeout);
+ AEDisposeDesc(&evt);
+ if (err) {
+ NSLog(@"AESendMessage failed: %d\n", err);
+ return err;
+ }
+ // Check for any application errors
+ err = AEGetParamDesc(&res, keyErrorNumber, typeSInt32, &desc);
+ AEDisposeDesc(&res);
+ if (!err) {
+ AEGetDescData(&desc, &err, sizeof(err));
+ NSLog(@"Terminal returned an error: %d", err);
+ AEDisposeDesc(&desc);
+ } else if (err == errAEDescNotFound) {
+ err = noErr;
+ } else {
+ NSLog(@"AEGetPArmDesc returned an error: %d", err);
+ }
- /* send the command event to Terminal.app */
- err = AESend(&theAEvent, &theReply, kAEWaitReply,
- kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
-
- if (err != noErr) {
- NSLog(@"doscript: AESend(docommand): error %d\n", err);
- goto bail;
- }
- /* clean up and leave */
-bail:
- AEDisposeDesc(&commandDesc);
- AEDisposeDesc(&theAEvent);
- AEDisposeDesc(&terminalAddress);
- AEDisposeDesc(&theReply);
- return err;
+ return err;
}