How to do I tell Quicktime player to start a New Movie Recording with a apple script

applescriptquicktimevideo

I have made a duplicate of the application "Quicktime player" on my Mac and renamed it "Reaction" then I have put this copy inside of a applescript. I am trying to write a code that tells the "Reaction" to start a "New Movie Recording" (which is a option of recording) then save the recording within the applescript. (the name of the recording is irrelevant)

Extra: Also if anyone knows how I could then code a way to add the recording to a email and send it to people that would be great.

At the moment I know how to open "Reaction" but not how to tell "Reaction" to start a "New Movie Recording"

So far i'm using this to open "Reaction"

  set appPath1 to path to resource "Reaction.app"
tell application "Finder"


open appPath1

end tell

Best Answer

Having duplicated your QuickTime Player application and named it Reaction, I understand you've created an AppleScript applet, and placed this copy of Reaction.app within the Resources folder of the AppleScript applet.

Because it's a duplicate of QuickTime Player (which is scriptable), Reaction is also scriptable, and can also be scripted from within the applet's AppleScript (located at Resources/scripts/main.scpt).

Your main.scpt should look something like this:

set A to path to resource "Reaction.app"

set home to POSIX path of (path to home folder)
set fp to home & "/Movies/Reaction Recording.mov"
set f to a reference to POSIX file fp

using terms from application "QuickTime Player"
    tell the application named A
        activate
        tell the (new movie recording)
            start
            delay 10
            pause
            save in f
            stop
            close
        end tell
    end tell
end using terms from

application "QuickTime Player" may change of its own accord to application "Reaction", which is completely fine.

This script creates a ~10 second recording, minus a couple of seconds to account for the initialisation of the script and such. Change delay 10 to whatever value represents a sensible recording time in seconds.

To send it as an attachment using Mail:

set msgSubject to "My Reaction Recording"
set msgBody to "Hi. Please see the attached recording. \n"
set msgFrom to "your@email.com"
set msgTo to "friend@email.com"

tell application "Mail"
    activate
    tell (make new outgoing message ¬
        with properties {visible:true ¬
        , subject:msgSubject ¬
        , content:msgBody ¬
        , sender:msgFrom})

        make new to recipient ¬
            at end of to recipients ¬
            with properties {address:msgTo}

        tell its content to make new attachment ¬
            at after the last paragraph ¬
            with properties {file name:f as alias}

        delay 2

        -- send
    end tell
end tell

The top script and the bottom script can simply join to form one continuous script. You might need a delay in between the two portions, but I didn't require one on my system.

However, the delay within the Mail block is important if you wish to send the email (you must also uncomment the send command by removing the --; keeping it in, which I did during testing, will allow you to preview the email and send it manually).