First stab at the launcher application. This will be run when the user
doubleclicks a .py, .pyw or .pyc file. It runs the file by invoking the
relevant interpreter (either the command line Python in a terminal window
or a Python.app for GUI-based scripts). Interpreter to use and the options
to pass are settable through preferences.

If PythonLauncher wasn't running it does its thing for one script and exits.
If it was manually started before a dialog is presented where the user
can set the options to use, etc.

To be done:
- option-drag/doubleclick should always open the interactive dialog
- Terminal-window isn't done yet
- Should be reimplemented in Python, but pyobjc isn't part of the core.
- Various menu entries should be disabled.
diff --git a/Mac/OSX/PythonLauncher/MyAppDelegate.m b/Mac/OSX/PythonLauncher/MyAppDelegate.m
new file mode 100644
index 0000000..107e7d0
--- /dev/null
+++ b/Mac/OSX/PythonLauncher/MyAppDelegate.m
@@ -0,0 +1,64 @@
+#import "MyAppDelegate.h"
+#import "PreferencesWindowController.h"
+
+@implementation MyAppDelegate
+
+- (id)init
+{
+    self = [super init];
+    initial_action_done = NO;
+    should_terminate = NO;
+    return self;
+}
+
+- (IBAction)showPreferences:(id)sender
+{
+    [PreferencesWindowController getPreferencesWindow];
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification *)notification
+{
+    // If we were opened because of a file drag or doubleclick
+    // we've set initial_action_done in shouldShowUI
+    // Otherwise we open a preferences dialog.
+    if (!initial_action_done) {
+        initial_action_done = YES;
+        [self showPreferences: self];
+    }
+}
+
+- (BOOL)shouldShowUI
+{
+    // if this call comes before applicationDidFinishLaunching: we do not show a UI
+    // for the file. Also, we should terminate immedeately after starting the script.
+    if (initial_action_done)
+        return YES;
+    initial_action_done = YES;
+    should_terminate = YES;
+    return NO;
+}
+
+- (BOOL)shouldTerminate
+{
+    return should_terminate;
+}
+
+- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
+{
+    return NO;
+}
+
+
+- (BOOL)application:(NSApplication *)sender xx_openFile:(NSString *)filename
+{
+    initial_action_done = YES;
+    return YES;
+}
+
+- (BOOL)application:(id)sender xx_openFileWithoutUI:(NSString *)filename
+{
+    initial_action_done = YES;
+    return YES;
+}
+
+@end