Automator Start Capture action doesn't detect stop in Quicktime in OS X 10.8.2

I am attempting to create an Automator application that will launch Quicktime, create a new audio capture, start that capture, and then save it with a specific filename after the stop button is clicked in the capture window. Although I was able to do this in Lion without any difficulty, I keep running into problems with the Start Capture action in Mountain Lion. Even though the "Wait for capture to complete" checkbox is checked, the action doesn't seem to detect when the stop button is clicked in Quicktime. Any solutions, tricks, or workarounds that would get this working properly would be greatly appreciated!


Solution 1:

There's a lot that doesn't work with respect to automating QuickTime under Mountain Lion. This is ugly, but it appears to be a workaround that has the key virtue of actually working.

In your automator flow, use the action "Run AppleScript". Use this as the script:

tell application "QuickTime Player"
    activate
    set x to new audio recording
    tell x to start
    delay 1
    set lastLength to duration of x
    delay 1
    set newLength to duration of x
    try
        repeat while lastLength is not equal to newLength
            delay 1
            set lastLength to newLength
            set newLength to duration of x
        end repeat
    end try
    --  display alert name of document 1
    set v to file of front document
    set thePath to POSIX path of (path to desktop)
    tell x to activate
    delay 1
    tell application "System Events"
        keystroke "S" using {command down, shift down}
        delay 1
        keystroke thePath
        delay 1
        keystroke return
        delay 1
        keystroke "specific file name"
        keystroke return
    end tell
end tell

This isn't pretty, but it's a workaround.

Just about all the code-based ways to script the save command in QuickTime via AppleScript appear to be broken in Mountain Lion. I can't access the path of the frontmost document. I can't export. I can't close saving. It all fails either silently or with an error message. What does seem to work is to send the appropriate keystrokes to simulate a manual file export. So that's what I've done here.

I suspect you want your file saved with a name different than "specific file name" and perhaps somewhere other than your desktop. Make the appropriate substitutions in the script so that can happen. The file will then be there on disk; subsequent actions in your workflow can take advantage of it.

Note that if your file already exists, you'll get a confirmation dialog in the QT save command, and the script doesn't handle that automatically.