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.
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:
If lockfile is found, a recording is active, so stop the recording and remove the lock file.
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.
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...
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:
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```