Capture One and the Recipe Open With

In a previous article I wrote about how to use keywords and smart albums to keep track of exports to specific locations in a more or less Lightroom Publishing Service kind of way. In this article I’m going to talk a bit about how we can draw on Capture One’s ability to run apps after image has been exported to post process the exported images.

The legendary Jeffrey Friedl, who has written more plugins for Lightroom than actually exist, wrote a nice little Lightroom plugin that runs a script on images after they’ve been exported. Lightroom users have been using it for some time to do stuff like sending images out by email, zipping, adding keywords, borders, etc and it got me to thinking on whether something similar could be done in Capture One.

Jeffrey’s plugin allows for scripts – shell, Python and whatnot. Capture One already has an Open With option on export recipes but only allowing the use of apps. However, AppleScript – sorry folks, no Windows here today – can create droplets. Droplets are AppleScript applets that process items that are dropped onto them. Droplets are essentially apps and so are recognised by Capture One in the Open With field. 

 

The only difference between an AppleScript script and a droplet is that a droplet is a script with an open handler that has been saved from the Script Editor as an app.

Here’s a pointless example:

on open the_items
	repeat with the_item in the_items
		-- Do Groovy Stuff to the_item here
		display alert ("Image Path is: " & the_item)
	end repeat
end open

Paste the script into the Script Editor. Save it as an app: File->Export, set the File Format dropdown in the save dialog to “Application” and set options as below:

  • Show startup screen: Off
  • Stay open after run handler: Off
  • Run-only: Off

Save it as an app, as described above then, back in Capture One, select ‘Other’ in the Open With dropdown menu in the Process Recipe Basic tab, browse to and select the app you’ve just created.

Now, for every file you export using this recipe, you’ll get a pointless alert pop up showing the path to the exported image.

Let’s look at some actual, useful examples.

Tweeting

Here’s an easy one to get going with; passing the exported image to a Twitter client. The native Twitter app isn’t so hot on scripting so in this example we’re using Tweetbot, which is better. You’ll need to download and install it before running this script.

 Here’s the script. Again, paste it into the Script Editor, save it as an Application and add it to a CO process recipe Open With: 

on open these_items
	
	repeat with this_item in these_items
		
		set the item_info to info for this_item
		
	-- get the typeID of the file
		try
			set typeID to the type identifier of item_info
		on error errStr number errorNumber
			display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
			return
		end try
		
	-- Tweet only if it’s a jpeg
		if typeID = "public.jpeg" then
			try
				-- Open the exported image in Tweetbot
				tell application "Tweetbot"
					open this_item
				end tell
				
			on error errStr number errorNumber
				display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
			end try
		end if
		
	end repeat
end open

The magic is in the lines shown below. Tweetbot is told to and opens each exported image in its own Tweet window. Just add some text and post.

tell application "Tweetbot"
	open this_item
end tell 

 It’s a little longer than the pointless example because I’ve added some error checking code to check that the files dropped onto the droplet are jpegs but it’s essentially the same script, used in exactly the same way. 

Instagram

 Instagram doesn’t allow you to post images from a computer, there’s not a lot we can do about that but we can make it easier. The currently accepted tool for moving images from a computer to Instagram is Dropbox. Export your shots into a Dropbox folder then, on your iPhone or iPad use the Dropbox app to save the shots into the iPhone gallery then post from the gallery to Instagram. Using AppleScript on a Mac, though, we can drop images directly into the Photos app. Photos automatically syncs to the cloud; after a short pause, the images appear in your iPhone gallery and are accessible directly from Instagram

Here’s the section of code that does the donkey work. For added convenience we create an Instagram folder in Photos if it doesn’t exist and place the exported image into it:

tell application "Photos"
	if not (exists container named DestinationAlbumName) then
		make new album named DestinationAlbumName
	end if

	import (the_item as alias) into container named "Instagram" with skip check duplicates
		
end tell

Here’s the full script, with error trapping as in the Twitter script. Usage is just the same; make sure it’s saved as an app, and add it to a Capture One process recipe Open With

on open these_items
	
	repeat with this_item in these_items
		
		set the item_info to info for this_item
		
		try
			
			set typeID to the type identifier of item_info
			
		on error errStr number errorNumber
			
			display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
			return
			
		end try
		
		if typeID = "public.jpeg" then
			try
				tell application "Photos"
					if not (exists container named "Instagram") then
						make new album named "Instagram"
					end if
					import (this_item as alias) into container named "Instagram" with skip check duplicates
					
				end tell
				
			on error errStr number errorNumber
				
				display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
				
			end try
			
		end if
		
	end repeat
end open
 

Add a Border

 You know those groovy little thin, black borders you see added to some Instagram images. This can be done in AppleScript using Image Events. Image Events is essentially sips, the command line image processing system that comes with OS X, in AppleScript. You can do a bunch of stuff with Image Events; resize, flip, rotate, crop. The command we’re interested in is pad. Pad adds coloured space around an image. For a border, the coloured space will be thin and black. Again, here’s the business part of the script that sits in our image loop:

tell application "Image Events"
				
	set this_image to open the_item
		
	set padding to 20
	pad this_image to dimensions {x + padding, y + padding} with colour #000000
		
	save this_image with icon
	close this_image
		
end tell

We have a slight problem here; the dimensions argument to pad is in pixels. We need to set the border width as a proportion of the actual image size otherwise the border is going to look much larger on a smaller image than on a larger one. To set this right we’ll do a bit of arithmetic and set the border width as a percentage:

set {x, y} to dimensions of this_image -- get the xy size of the image in pixels
		
if x is greater than y then
	set padding to borderSize / 100 * x
else
	set padding to borderSize / 100 * y
end if
		
pad this_image to dimensions {x + padding, y + padding}

And once again, the full script.

 

on open these_items
	
	repeat with this_item in these_items
		
		set the item_info to info for this_item
		
		try
			
			set typeID to the type identifier of item_info
			
		on error errStr number errorNumber
			
			display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
			return
			
		end try
		
		if typeID = "public.jpeg" then
			try
				tell application "Image Events"
				
				set this_image to open the_item
				
				set {x, y} to dimensions of this_image -- get the xy size of the image in pixels
				set borderSize to 0.75
		
				if x is greater than y then
					set padding to borderSize / 100 * x
				else
					set padding to borderSize / 100 * y
				end if
		
			pad this_image to dimensions {x + padding, y + padding}
		
				save this_image with icon
				close this_image

			on error errStr number errorNumber
				
				display dialog "Droplet ERROR: " & errStr & ": " & (errorNumber as text)
				
			end try
			
		end if
		
	end repeat
end open

In Conclusion

I’ve never felt that the export recipe tab’s Open With feature, constrained as it is to apps, has been of much use but by bringing AppleScript to the party in the way we have here, whole new avenues have been opened. App development is cumbersome and difficult. AppleScript scripting, on the other hand, is much simpler, much more suited to developing quick tools in a working environment. AppleScript is also powerful. As we’ve seen here it can dip into many things, drive many applications. If there’s anything at all that you’d want to do to images after you’ve exported them, this method can probably handle it. If anyone has some interesting ways to use it, please do share in the comments section below.

As I complete this article I’ve been automating the process of exporting and uploading images to my website, a self hosted WordPress site. WordPress allows images and posts to be uploaded remotely using the XMLRPC protocol. The next blog post I’ll be talking about how I’ve used a combination of AppleScript and PHP to upload images to a WordPress site.

 

 

 

 

 

  • You are missing an “end tell” in the border script.

  • kimaldis

    Got it, thanks.

  • Where does borderSize get set?

  • kimaldis

    I’ve added a set borderSize line in the code. Sorry for the messing about, I’ll check the code more carefully next time.

  • Stuart Flisher

    Thank for the script sample. Is there an option to run a script against the ‘Edit With’ option? I would like to open with photoshop and run a photoshop action. I can do this using your script but ‘Open With’ bypasses the C1 raw conversion and therefore uses Adobe Camera Raw which I want to avoid.

Pin It on Pinterest

Share This