Mercurial > my-enso-commands
comparison my-enso-commands.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 7:41bc59775872 | 8:4285e37bea69 |
|---|---|
| 52 def _get_filelike_timestamp(): | 52 def _get_filelike_timestamp(): |
| 53 import time | 53 import time |
| 54 | 54 |
| 55 return time.strftime("%Y%m%d%H%M%S") | 55 return time.strftime("%Y%m%d%H%M%S") |
| 56 | 56 |
| 57 def _get_current_app(): | |
| 58 import AppKit | |
| 59 | |
| 60 app = AppKit.NSWorkspace.sharedWorkspace().activeApplication() | |
| 61 return app.objectForKey_("NSApplicationBundleIdentifier") | |
| 62 | |
| 63 def maybe_export_photoshop_clipboard(func): | |
| 64 def wrapper(*args, **kwargs): | |
| 65 if _get_current_app() == 'com.adobe.Photoshop': | |
| 66 _runAppleScript('tell application "Adobe Photoshop CS3" ' | |
| 67 'to copy merged') | |
| 68 _runAppleScript('tell application "Finder" to activate') | |
| 69 retval = func(*args, **kwargs) | |
| 70 _runAppleScript('tell application "Adobe Photoshop CS3" ' | |
| 71 'to activate') | |
| 72 return retval | |
| 73 return func(*args, **kwargs) | |
| 74 return wrapper | |
| 75 | |
| 76 @maybe_export_photoshop_clipboard | |
| 57 def _get_clipboard_img_datafile(): | 77 def _get_clipboard_img_datafile(): |
| 58 import AppKit | 78 import AppKit |
| 59 | 79 |
| 60 pb = AppKit.NSPasteboard.generalPasteboard() | 80 pb = AppKit.NSPasteboard.generalPasteboard() |
| 61 typestr = pb.availableTypeFromArray_([AppKit.NSTIFFPboardType, | 81 typestr = pb.availableTypeFromArray_([AppKit.NSTIFFPboardType, |
| 746 ensoapi.set_selection( {"html":"<b>hi</b> <p>there</p>"} ) | 766 ensoapi.set_selection( {"html":"<b>hi</b> <p>there</p>"} ) |
| 747 | 767 |
| 748 def _runAppleScript( script ): | 768 def _runAppleScript( script ): |
| 749 params = [ "osascript", "-e", script ] | 769 params = [ "osascript", "-e", script ] |
| 750 popen = subprocess.Popen( params ) | 770 popen = subprocess.Popen( params ) |
| 771 if popen.wait(): | |
| 772 raise Exception("Applescript failed: %s" % script) | |
| 751 | 773 |
| 752 def cmd_screen_saver(ensoapi): | 774 def cmd_screen_saver(ensoapi): |
| 753 """ | 775 """ |
| 754 Starts your screen saver. | 776 Starts your screen saver. |
| 755 """ | 777 """ |
