Tuesday, February 23, 2010

Controlling the Canon EOS Utility using AppleScript

The Canon EOS Utility is a great piece of software especially when you consider that it comes free with every Canon EOS DSLR. Its Remote Live View shooting window gives you a decent monitor image and lets you even start and stop video recording on all cameras that have the EOS Movie function.



The EOS Utility is not directly accessible using AppleScript but you still can control it using GUI scripting. The AppleScript below e.g. clicks on the "Prepare the camera for movie recording" button at the lower left corner of the Remote Live View window.

To find the pixel coordinates of a button press SHIFT COMMAND 4 on the keyboard. This activates the screenshot utility and if you place the cursor over a button you can see its pixels coordinates. Note the numbers and press ESC.

You must "Enable access for assistive devices" in System Preferences > Universal Access in order to use the scripts below.

Tested with OS X 10.4 and 10.5 only:
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click at {38, 700} --x,y screen coordinates. 0,0 is at the upper left corner.
end tell
end tell


When you run this AppleScript (with the button coordinates of your screen!) you will notice the line
checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"

in the "Result" area at the bottom of the Script Editor window. This is the actual AppleScript reference to this button that can be used in an AppleScript that is now independent of the window size of the EOS Utility.

tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell

Or just for fun the entire script in two command lines
tell application "EOS Utility" to activate
tell application "System Events" to tell process "EOS Utility" to click checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"

The following script allows timed recordings:

on enable()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
delay 1
end enable

on rec()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click checkbox 2 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
delay 2
end rec

enable()
rec()
delay 10 --record for 10 seconds
rec()
enable()


The next example clicks repeatedly on the <<< and >>> Focus buttons to simulate a focus pull from the background to the foreground and back again. It's not very smooth and repeatable though.



on enable()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
delay 1
end enable

on rec()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click checkbox 2 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
delay 2
end rec

on focusNear3()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click button 8 of group 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
end focusNear3

on focusFar3()
tell application "EOS Utility" to activate
tell application "System Events"
tell process "EOS Utility"
click button 9 of group 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
end tell
end tell
end focusFar3

enable()
rec()
delay 3
repeat 4 times
focusFar3()
end repeat
delay 3
repeat 4 times
focusNear3()
end repeat
delay 3
rec()
enable()



Before you ask, yes I've tried to start movie recording and QuickTime audio recording at the same time via AppleScript. It works but it's impossible to get video and audio synced automatically. The delays are too long.

10 comments:

  1. Hi Martin, I am trying to use the script for start/stop movie recording using the screen coordinates. I pasted the script and plugged in my x,y coordinates of 60 and 975 where you have 30 and 700. hit run and it gives me a "missing value"

    here is what I have:
    tell application "System Events"
    tell process "EOS Utility"
    click at {60, 975} --x,y screen coordinates. 0,0 is at the upper left corner.
    end tell
    end tell

    and it gives me this:
    tell application "System Events"
    click process "EOS Utility" at {60, 975}
    --> missing value
    end tell
    Result:
    missing value


    Any idea what is wrong. I am very new to this.

    ReplyDelete
  2. Hi Troy, I can't see any mistake. I used OS X 10.4 and 10.5

    Does this work (It's the approach better anyway)?:

    tell application "System Events"
    tell process "EOS Utility"
    click checkbox 1 of window "Remote Live View window" of application process "EOS Utility" of application "System Events"
    end tell
    end tell

    ReplyDelete
  3. Hi Martin, this is great! Can you please tell me how to make the script repeat itself? I would like my camera to stop recording every ten minutes and start recording again immediately. Thanks! Hans

    ReplyDelete
  4. Hans, just put the code between "repeat" and "end repeat". Since this loops forever ou must end the script with Command . (that's Command+period).

    ReplyDelete
  5. Hello Martin,

    Great explanation... I am trying to use this method to automate the changing of the shutter speed for a time-lapse project. Using this method returns a "missing value" result. I found an alternative to EOS Utility called DSLR Assistant. It allows me to access the pop-up menu for the shutter speed (TV) but I haven't figured out how to select the items. "click menu item 1" returns something about a bad "Index".

    I'm not sure you intended this blog to turn into a forum, and I don't know if you have a suggestion... but I figured you are 3/8th of the way there so here I am asking.

    ReplyDelete
  6. marq5, I just ran the script under Snow Leopard which I installed recently and yes I also got the missing value error. To make it work with 10.6 I had to add the line "tell application "EOS Utility" to activate"
    This should work:

    tell application "System Events"
    tell application "EOS Utility" to activate
    tell process "EOS Utility"
    click at {38, 700} --x,y screen coordinates. 0,0 is at the upper left corner.
    end tell
    end tell

    ReplyDelete
  7. I'm running 10.6.7 but I don't think that is the reason it's still not working for me. I'm still getting a "missing value" error when I use the click at {x, y} method with EOS Utility.

    Using the activate command doesn't help with DSLR Assistant either. But at least the pop-up (pop up button) menu appears and I can see what it is called. I think I'm just stumbling on how to click on the value I want from that menu.

    Thanks for you input. Here is my (failed) attempt to click on the 3rd item in the pop up button.

    tell application "System Events"
    tell application "DSLR Assistant" to activate
    tell process "DSLR Assistant"
    click pop up button 3 of scroll area 1 of group 1 of window " [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II" of application process "DSLR Assistant" of application "System Events"
    click menu item 3 of pop up button 3 of scroll area 1 of group 1 of window " [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II" of application process "DSLR Assistant" of application "System Events"
    end tell
    end tell

    Result is:

    error "„System Events“ encountered an error: „menu item 3 of pop up button 3 of scroll area 1 of group 1 of window \" [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II\" of application process \"DSLR Assistant\"“ can't be read. Invalid Index." number -1719 from menu item 0 of pop up button 3 of scroll area 1 of group 1 of window " [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II" of application process "DSLR Assistant"

    "pop up button" is what the "click at {x, y}" method returned, so that is probably not the problem. I'm pretty sure that there has to be another way to designate the value of the button than with "click menu item"... but what?

    ReplyDelete
  8. Okay, I think that I have found a solution:

    tell application "System Events"
    tell application "DSLR Assistant" to activate
    tell process "DSLR Assistant"
    click pop up button 3 of scroll area 1 of group 1 of window " [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II" of application process "DSLR Assistant" of application "System Events"
    keystroke "1/200"
    keystroke return
    end tell
    end tell

    By keystroking the value as it is written in the pop up button I am able to select it. Then Keystroking return closes the pop up button with the new value. Only problem is; that there are values like 0"3 which confuse the keystroke command because it uses the " itself. Oh-well, if I keystroke "0" it selects the first 0 value... I could live with that. Now I just have to figure out how to have it execute at a specific time and I'm set.

    Thanks Martin for starting this Blog.

    Cheers,

    DK

    ReplyDelete
  9. My scripts worked well with 10.4 and 10.5 but now I have a problem because I don't have my Canon EOS DSLR any longer and therefore can't test it with the EOS Utility (the Live View Window only opens when a camera is connected). Sorry for that.
    I used another app (BBEdit) for testing today and the solution was to activate the app.

    The following script for example clicks on "File" and then on "Open" in BBEdit:

    tell application "BBEdit" to activate
    tell application "System Events"
    tell process "BBEdit"
    click menu bar item "File" of menu bar 1 of application process "BBEdit" of application "System Events"
    click menu item "Open…" of application process "BBEdit" of application "System Events"
    end tell
    end tell

    I think you are close. Maybe you just have to use the name of the menu item. If you find the solution please be so kind to post it here. Thanks.

    ReplyDelete
  10. I think that Canon's EOS Utility has some special protections to prevent too much fiddling around with it.

    I found a very good solution using DSLR Assistant. Here is the best script so far:

    tell application "System Events"
    tell application "DSLR Assistant" to activate
    tell process "DSLR Assistant"
    set downArrow to ASCII character 31
    set upArrow to ASCII character 30
    click pop up button 3 of scroll area 1 of group 1 of window " [Unregistered] DSLR Assistant - Connected to Canon EOS 5D Mark II" of application process "DSLR Assistant" of application "System Events"
    keystroke downArrow
    keystroke return
    end tell
    end tell

    I will work on scheduling it to run using iCal.

    Thanks again for making this Blog.

    Grüße aus Frankfurt,

    DK

    ReplyDelete