This is a small utility workflow for Editorial to display the current clipboard contents in the console. But I don't want to just see text. If there's an image on the clipboard, I want to see that too. This workflow handles that.
I've chosen not to clear the console with each run. I like to use the console like a little scratch log as I work. Feel free to change that behavior if you prefer a clean console each time.
The current text on the clipboard is display in orange on the console. If there's an image, it is also displayed on the console.
The trick here is to use the Clipboard module in Editorial and check to see if it contains an image. Here's the Python script:
#coding: utf-8 import workflow import clipboard import console import Image clip_image = clipboard.get_image() clip_text = clipboard.get() if not clip_image: console.set_color((float(238)/255), (float(154)/255), (float(0)/255)) print clip_text else: clip_image.show()
Here's what's going on. We capture the clipboard contents in two different ways. This is a bit wasteful, but the iPad can handle it. If there's an image on the clipboard, the clipboard.get_image() method will grab it as a PIL object. If there's just text on the clipboard then this method will return None.
We test to see if clip_image is None in the next if not clip_image statement. This just says if clip_image is empty then there wasn't an image on the clipboard. In this case we use the text we grabbed off of the clipboard with clip_text = clipboard.get(). If there is an image, we jump to the clip_image.show() line that displays the image in the console.
The little touch here is to use the console module to make our text orange on the console. Since the console.set_color() method expect RGB values from 0 to 1, we need to convert standard RGB values of 0 to 255. That's accomplished with some basic math.
If you've read this far you've probably figured out that this post wasn't so much about sharing a workflow. It's a mini tutorial for using some of the basic Python methods in Editorial. I figured that was generally more useful to people that feel a bit overwhelmed with making Editorial do amazing new things.