changeset 8:4285e37bea69

added workaround for getting photoshop merged selection, applescript failures now raise exceptiosn
author Atul Varma <varmaa@toolness.com>
date Sat, 27 Mar 2010 12:51:29 -0700
parents 41bc59775872
children e5402ead0307
files my-enso-commands.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/my-enso-commands.py	Sat Mar 27 12:19:32 2010 -0700
+++ b/my-enso-commands.py	Sat Mar 27 12:51:29 2010 -0700
@@ -54,6 +54,26 @@
 
     return time.strftime("%Y%m%d%H%M%S")
 
+def _get_current_app():
+    import AppKit
+
+    app = AppKit.NSWorkspace.sharedWorkspace().activeApplication()
+    return app.objectForKey_("NSApplicationBundleIdentifier")
+
+def maybe_export_photoshop_clipboard(func):
+    def wrapper(*args, **kwargs):
+        if _get_current_app() == 'com.adobe.Photoshop':
+            _runAppleScript('tell application "Adobe Photoshop CS3" '
+                            'to copy merged')
+            _runAppleScript('tell application "Finder" to activate')
+            retval = func(*args, **kwargs)
+            _runAppleScript('tell application "Adobe Photoshop CS3" '
+                            'to activate')
+            return retval
+        return func(*args, **kwargs)
+    return wrapper
+
+@maybe_export_photoshop_clipboard
 def _get_clipboard_img_datafile():
     import AppKit
 
@@ -748,6 +768,8 @@
 def _runAppleScript( script ):
     params = [ "osascript", "-e", script ]
     popen = subprocess.Popen( params )
+    if popen.wait():
+        raise Exception("Applescript failed: %s" % script)
 
 def cmd_screen_saver(ensoapi):
     """