19 July 2017

Every once and a while I have the need to focus stack a slightly larger object than my normal macro lenses will allow. In these situations I will just use a normal lens mounted on my camera, sometimes with a diopter on top. This can become both a blessing and a curse. A blessing because turning the lens focus ring is normally better than moving the whole camera. A curse because that means I shouldnt use Focus Stepper.

While there are a few paid solutions for stepping focus automatically with the camera's auto focus, I have found it more reliable to script EOS Utility to do it.

To beguin we just need to open up the Script Editor, EOS Utility, and finally UI Browser, The trial version works well enough for our needs, and can be found at http://pfiddlesoft.com/uibrowser/ . Apple also provides an Accessibility Inspector, but scripting with AX elements can be finicky some times, so we'll avoid that. When you first launch UI Browser, you need to go to System Preferences > Security and Privacy > Privacy > Accessibility and select it to allow it to control your computer. You also will need to do the same thing with Script Editor.

With everything open and running, step one is to identify the UI elements we want to control. Click "Switch to Screen Reader" in UI Browser and hover over the focus buttons to get the button names and the window.

Button and Window names, and we are all set!

Now that we have the information we need, we can start scripting.

Ill start by making a dialog that lets me set the number of images and which focus button to use. Since I only ever shoot front to back, I wont worry about the reverse focus buttons.

set repeatNumber to text returned of DIALOG_1<br />
set btnPress to button returned of DIALOG_1<br />
delay (6)

With the dialog out of the way, we can do the actual work. We will take the repeatNumber we set in the dialog and repeat out action this number of times.

repeat repeatNumber times

Then we need to make sure EOS utility is in focus using the activate command. I do this in the loop so that incase I accidentally click away from EOS Utility while the script is running, it will switch back when it needs to. Next we take out first photo before we step focus. The space key takes an image in EOS Utility, so I use that keystroke instead of fiddlign aroudn with the shutter button in the UI. Finally a short delay to let the camera to do all its mechanical stuff.

activate application "EOS Utility 3"<br />
tell application "System Events" to tell process "EOS Utility 3" to keystroke " "<br />
delay (2)

Now To step focus based on what we pressed in the dialog. There are a few options for doing this, but I ended up putting the elseif inside of the loop. A smarter person in less of a rush would have added the elseif before the loop and assigned the result to a new variable. Then used that variable inside the loop. It aint scripting if your doing it right 😉 Then a small delay. This is so we have a short rest period between when the lens moves and when the shutter fires.

tell application "System Events" to tell process "EOS Utility 3"
		if btnPress = "Fine" then
			click button 14 of window 1
		else if btnPress = "Medium" then
			click button 11 of window 1
		else if btnPress = "Course" then
			click button 12 of window 1
		end if
	end tell
	delay (0.75)

End our loop

end repeat

And let us know that the script has completed

display dialog "Complete" buttons {"OK"} default button 1

Improvements you can make!: