--- plug-ins/common/screenshot.c.orig	2012-05-08 08:05:46.000000000 +0200
+++ plug-ins/common/screenshot.c	2012-10-14 15:09:58.000000000 +0200
@@ -19,6 +19,7 @@
  *  Screenshot plug-in
  *  Copyright 1998-2007 Sven Neumann <sven@gimp.org>
  *  Copyright 2003      Henrik Brix Andersen <brix@gimp.org>
+ *  OS X patches 2012   copyright 2012 Simone Karin Lehmann
  *
  *  Any suggestions, bug-reports or patches are very welcome.
  *
@@ -28,6 +29,10 @@
 
 #include <string.h>
 
+#ifdef PLATFORM_OSX
+#include <stdlib.h>
+#endif
+
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
@@ -173,7 +178,11 @@
 static ScreenshotValues shootvals =
 {
   SHOOT_WINDOW, /* root window  */
+#ifdef PLATFORM_OSX
+  FALSE,
+#else
   TRUE,         /* include WM decorations */
+#endif
   0,            /* window ID    */
   0,            /* select delay */
   0,            /* coords of region dragged out by pointer */
@@ -197,6 +206,8 @@
                                         const gchar      *name);
 
 static gint32     shoot                (GdkScreen        *screen);
+static gint32     shoot_main           (GdkScreen        *screen);
+static gint32     shoot_osx            (GdkScreen        *screen);
 static gboolean   shoot_dialog         (GdkScreen       **screen);
 static void       shoot_delay          (gint32            delay);
 static gboolean   shoot_delay_callback (gpointer          data);
@@ -245,7 +256,15 @@
                           "may grab the root window or use the window-id "
                           "passed as a parameter.  The last four parameters "
                           "are optional and can be used to specify the corners "
-                          "of the region to be grabbed.",
+                          "of the region to be grabbed."
+#ifdef PLATFORM_OSX						  
+                          "On Mac OS X, when called non-interactively, the plugin"
+                          "only can take screenshots of the entire root window."
+                          "Grabbing a window or a region is not supported"
+                          "non-interactively. To grab a region or a paticular"
+                          "window, you need to use the interactive mode."
+#endif
+                          ,
                           "Sven Neumann <sven@gimp.org>, "
                           "Henrik Brix Andersen <brix@gimp.org>",
                           "1998 - 2008",
@@ -324,7 +343,11 @@
 
       if (! gdk_init_check (NULL, NULL))
         status = GIMP_PDB_CALLING_ERROR;
-      break;
+#ifdef PLATFORM_OSX
+        if (shootvals.shoot_type == SHOOT_WINDOW || shootvals.shoot_type == SHOOT_REGION) 
+            status = GIMP_PDB_CALLING_ERROR;
+#endif
+        break;
 
     case GIMP_RUN_WITH_LAST_VALS:
       /* Possibly retrieve data from a previous run */
@@ -335,6 +358,7 @@
       break;
     }
 
+#ifndef PLATFORM_OSX
   if (status == GIMP_PDB_SUCCESS)
     {
       if (shootvals.select_delay > 0)
@@ -348,6 +372,7 @@
             status = GIMP_PDB_CANCEL;
         }
     }
+#endif
 
   if (status == GIMP_PDB_SUCCESS)
     {
@@ -925,6 +950,20 @@
 static gint32
 shoot (GdkScreen *screen)
 {
+#ifdef PLATFORM_OSX
+    /* on Mac OS X, either with X11 (which is a rootless X server) or as a native quartz build,
+     * we have to implement it differently, without using X and just use the standard
+     * OS X screenshot utility.
+     */
+    return shoot_osx(screen);
+#else
+    return shoot_main(screen);
+#endif
+}
+
+static gint32
+shoot_main (GdkScreen *screen)
+{
   GdkDisplay      *display;
   GdkWindow       *window;
   cairo_surface_t *screenshot;
@@ -1029,6 +1068,62 @@
   return image;
 }
 
+/*
+ * Mac OS X uses a rootless X server. This won't let us use gdk_pixbuf_get_from_drawable() and similar 
+ * function on the root window to get the entire screen contents.
+ * With a nytive OS X build we have to do this without X as well.
+ * Since Mac OS X 10.2 a system utility for screencapturing is included. We can savely use this, since it's
+ * available on every OS X version, GIMP is running on.
+ * The main drawback are, that now it's not possible to shoot windows or regions in scripts in noninteractive mode,
+ * and that windows always include decorations, since decorations are different between X11 windows and native
+ * OS X app windows. But so we can us this switch to capture the shadow of a window, which is indeed very Mac-ish.
+ *
+ * This routines works well with X11 and as a navtive build
+ */
+static gint32
+shoot_osx (GdkScreen *screen)
+{
+    gint32      image;
+    gchar		*mode = " ";
+    gchar		*delay = NULL;
+    gchar		*cursor = " ";
+    gchar		*command = NULL;
+
+    switch (shootvals.shoot_type) {
+        case SHOOT_REGION:
+            mode = "-is";
+            break;
+        case SHOOT_WINDOW:
+            mode = "-iwo";
+            if (shootvals.decorate) {
+                mode = "-iw";
+            }
+            break;
+        case SHOOT_ROOT:
+            mode = " ";
+            break;
+        default:
+        break;
+    }
+
+    delay = g_strdup_printf("-T %i", shootvals.select_delay);
+
+    if (shootvals.show_cursor) {
+        cursor = "-C";
+    }
+
+    command = g_strjoin (" ", "/usr/sbin/screencapture", mode, cursor, delay, "/tmp/screenshot.png", NULL);
+    system((const char *)command);
+
+    image = gimp_file_load (GIMP_RUN_NONINTERACTIVE, "/tmp/screenshot.png", "/tmp/screenshot.png");
+    gimp_image_set_filename (image, "screenshot.png");
+
+    g_free(delay);
+    g_free(command);
+
+    return image;
+}
+
 /*  Screenshot dialog  */
 
 static void
