Sunday, June 13, 2021

#1 2021-05-10 06:05:37 pm

Beeman
Member
Registered: 2006-03-07
Posts: 81

Scripting application QuickTime Player

Hello everyone...
hope someone can help me with this issue. I had a script to control an QuickTime Player audio recording. But it stopped working in Big Sur

My script to start the audio recording still works...

tell application "QuickTime Player"
    activate
    set new_recording to (new audio recording)
    -- the name of document 1 becomes document "Audio Recording"
    delay 2
    tell new_recording
        start
    end tell
end tell

But since upgrading to Big Sur my script to pause the audio recording does not work...

tell application "QuickTime Player"
   
    activate
   
    try
       
        tell document "Audio Recording"
            pause
        end tell
        set nothingwentwrong to true
    on error
        set nothingwentwrong to false
    end try
   
end tell

I can't figure out why. I tried "pause  Document 1", but nothing works.

anyone have a suggestion

thank you Kevin

Offline

 

#2 2021-05-11 05:15:27 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 910

Re: Scripting application QuickTime Player

Kevin. I don't have a microphone attached to my computer and, for that reason, can't start an audio recording. However, I would suggest that you start a recording and run the following script in Script Editor. Either it should pause the recording or report an error, which would indicate the nature of the issue.

Applescript:

tell application "QuickTime Player" to tell document 1
   pause
end tell


2018 Mac mini - macOS Catalina

Offline

 

#3 2021-05-12 10:08:14 pm

Beeman
Member
Registered: 2006-03-07
Posts: 81

Re: Scripting application QuickTime Player

Hmm

I started a new Audio recording and pressed record.

Tried your suggested script and it did not pause it. It gives no error message, just does not do anything.

I am confused as "pause" is in the QuickTime app Dictionary

Offline

 

#4 2021-05-13 12:21:25 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: Scripting application QuickTime Player

The dictionary is lying. The "pause" command does not work. Whether this is a bug from Apple or is it done on purpose, I don't know.

In fact, the application requires the OPTION key to be pressed before attempting to pause. This is how it works:

Applescript:


tell application "QuickTime Player"
   activate
   set new_recording to (new audio recording)
   tell new_recording to start
   delay 5 -- WAIT RECORDING FOR 5 SECONDS
end tell

tell application "System Events"
   key down option -- REQUIRED
   tell application process "QuickTime Player" to tell window 1 to ¬
       click UI element 3 -- "||" (PAUSE BUTTON) OF RECORDING WINDOW
   key up option -- REQUIRED
end tell

tell application "QuickTime Player" to display dialog "AUDIO RECORDING IS PAUSED"

Last edited by KniazidisR (2021-05-13 12:31:12 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2021-05-13 05:54:01 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 40

Re: Scripting application QuickTime Player

I have no clue whether there is a Big Sur issue and for me, scripting QT Player is certainly a hassle. This script uses screen recordings rather than movie or audio but they should work similarly and don't have any dependencies.

It records for 4 seconds, pauses for 6, then records for 4 more. Note that there is some overhead in the process so you don't get four full seconds.

Applescript:

set ft to ((path to desktop) & "crap.mov" as text) as «class furl»
-- file "Mac:Users:username:Desktop:crap.mov"

tell application "QuickTime Player"
   activate
   close windows without saving
   set nsr to new screen recording
   tell nsr
       tell me to set nBeg to round (seconds of (current date)) + 2 rounding down
       start
       delay 4 -- record for 4 seconds less overhead
       pause -- pause recording for 6 seconds then resume
       delay 6
       resume
       delay 4 -- record for 4 seconds less overhead
       stop
       tell me to set nEnd to round (seconds of (current date)) - 1 rounding down
   end tell
   
   -- Export > 720p mov
   tell me to close access (open for access ft with write permission)
   set nrd to first document
   export nrd in ft using settings preset "720p"
end tell

-- Imprecise opening and closing seconds
-- (Your clock should be set to 'display the time with seconds' or this has no point)
display notification "Captured seconds between " & nBeg & " to " & nEnd

On my system, recording duration is about 6.6 seconds and spans a period of about 12 seconds. It's possible that if you set the delays to 4.7 seconds (4 + ((8-6.6)/2) then you might get 8 full seconds of recording (on my system the result was exactly 8000 ms smile) but that will likely throw off the notification's timings. Delete the extraneous lines at your convenience.

Offline

 

#6 2021-05-16 01:44:59 pm

Beeman
Member
Registered: 2006-03-07
Posts: 81

Re: Scripting application QuickTime Player

hmm

The script

tell application "System Events"
   key down option -- REQUIRED
   tell application process "QuickTime Player" to tell window 1 to ¬
       click UI element 3 -- "||" (PAUSE BUTTON) OF RECORDING WINDOW
   key up option -- REQUIRED
end tell


on my system the Key Down option does not work. The script simple stops the recording, but does not pause it

Kevin

Offline

 

#7 2021-05-16 02:02:34 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1878

Re: Scripting application QuickTime Player

Assuming the audio recording  run already, you don't need start recording from script, but "QuickTime Player" still should be on the front before its GUI scripting, because we want send commands to GUI of "QuickTime Player" and not to GUI of "Script Editor":

Applescript:


tell application "QuickTime Player" to activate -- THAT: is required

tell application "System Events"
   key down option -- REQUIRED
   tell application process "QuickTime Player" to tell window 1 to ¬
       click UI element 3 -- "||" (PAUSE BUTTON) OF RECORDING WINDOW
   key up option -- REQUIRED
end tell

Last edited by KniazidisR (2021-05-16 02:03:32 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#8 2021-05-16 02:24:02 pm

Beeman
Member
Registered: 2006-03-07
Posts: 81

Re: Scripting application QuickTime Player

Yes that works!

Note: The QuickTime dictionary also includes "resume" and "stop" which also DO NOT work

Kevin

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)