Is there a way to tell if QuickTime is recording?

I want to have macro that starts a QuickTime screen recording when cmd+option+control+N is pressed, but if a screen recording is already in progress, I want cmd+option+control+N to end the current screen recording.

Here is what I have so far:

Is there a condition that can determine if the recording is in process?

I just looked through the QuickTime dictionary for AppleScript, and I don't see anything that would tell you that a screen recording is happening or not.

Usually in these situations, I think a "lock file" is often used, with logic that goes something like this:

  1. If lockfile is found, a recording is active, so stop the recording and remove the lock file.

  2. If no lockfile is found, create one, and start a recording

Relatively low-tech and not fool-proof, but it's one way of handling it. Perhaps others will have better ideas.

1 Like

Very low-tech: check if there's an icon in the menu bar.

2 Likes

This will do the trick.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Toggle QuickTime Player Recording [Example]

--- VER: 1.0    2020-03-05 ---
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

Download: Toggle QuickTime Player Recording [Example].kmmacros

Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


1 Like

Thanks for your help. Unfortunately, I ran into a problem with this--quicktime does not disable the "New screen recording" menu while a screen recording is already active...

Did you actually test my macro?
It works for me.

Yes I tried it. When I press the shortcut for the second time, a new recording window comes up and the previous recording doesn't stop:

Yes, I can’t make it work either.

  • The menu doesn’t get disabled when a recording is in process
  • first document doesn’t seem to exist yet when a recording is in process

Maybe due to different QT versions? (I have QT Player 10.5 (1015.2.1))

Here another way to detect if a screen recording is in process:

New QT screen capture if not already running <9AC5 200306T154410>-pty-fs8
New QT screen capture if not already running <9AC5 200306T154410>.kmmacros (4.6 KB)

The macro tests if any screencapture process is running. Then it either stops the current recording or starts a recording.

Note that the process continues to run for a couple of seconds after stopping a screen recording.


Edit: Disabled the debug action and added the keystroke action for stopping.

Edit 2: Disabled the Activate QT action, which seems to be unnecessary.



PS:

Here (almost) the same as AppleScript:

tell application "System Events"
  if application process "screencaptureui" exists then
    key code 53 using {command down, control down}
    error number -128
  end if
end tell

tell application "QuickTime Player"
  new screen recording
end tell

A screen recording seems to spawn always two related processes:

/usr/sbin/screencapture
/System/Library/CoreServices/screencaptureui.app/Contents/MacOS/screencaptureui

The pgrep screencapture in the macro above checks for both, the AppleScript just for the second one. I don’t know what is better.

2 Likes

Hi,

I know this is an old post but I figured it might help someone out. Unfortunately I'm a pretty novice coder, but this works great (it's setup for movie recordings.

I assume it would be similar ¯_(ツ)_/¯

-- GETS the state of QT (ready, recording)
on qt_state()
	set isready to false
	set isrecording to false
	tell application "QuickTime Player"
		try
			get name of its front document
		on error
			activate
			new movie recording
		end try
		if (name of its front document is "Movie Recording") then
            --this essentially doesnt matter, just tells your program if it needs to do the new movie recording command
			set isready to true
			tell its front document
                -- "movie recoridng"'s duration returns "NaN" if not recording
				set dur1 to its duration
				if (dur1 as text is "NaN") then return {ready:isready, recording:false}
				delay 1
                --checks if the durations between 1s is the same- not recording
				set dur2 to its duration
				if (dur1 is dur2) then
					set isrecording to false 
				else
					set isrecording to true
				end if
			end tell
		end if
	end tell
	return {ready:isready, recording:isrecording}
end qt_state```