Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 1 down vote accepted
+200

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.

share|improve this answer

Rather than using the built-in start capture actions, use an AppleScript action as the trigger to start the recording (and wait for it to stop), then pass the resulting file to Automator to do whatever else you need with it.

I modified Daniel Lawson's script slightly:

tell application "QuickTime Player"
    activate
    new audio recording
    tell front document to start
    delay 1
    set lastLength to duration of front document
    delay 1
    set newLength to duration of front document
    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
    set theFile to file of front document
    return POSIX path of theFile
end tell

I removed the export lines1, and changed the references from a variable to simply the front document (which avoids some errors if the recording is short, which I ran into during my testing). Finally, I added a return statement with the POSIX path of the resulting file, which Automator can take as input for subsequent actions.

Put that in an AppleScript action, and the resulting file will be properly passed to any other actions you have (such as moving/renaming it, or re-encoding).

Notes

1 QuickTime Player's save and export AppleScript functions are broken to the point of being useless. My theory is that this happened when 10.7 introduced autosaving, as all recordings are automatically saved to your ~/Movies directory, and the quality settings need to be adjusted manually beforehand (they're not exposed to AppleScript).

share|improve this answer
    
Have you tested this in ML? I like the idea a lot, but I'm getting the same crash here as I did with the first version of my script. –  Daniel Lawson Dec 1 '12 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.