Skip to main content
added 403 characters in body; edited title
Source Link
mathlete
  • 162
  • 1
  • 8

AppleScript (to start screen recording) takes 96 to 15s12s to even start running. Why?

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s6s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s12s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I'm working on macOS 10.15.6 (Catalina)

Update

I did some more tests and it really seems to be the AppleScript that slows things down. If I install the command-line tool cliclick and assign cliclick kd:cmd,shift t:5 m:1205,989 kp:enter to a Quick-Action-based keystroke (which mimics the clicking sequence to start screen recording; you might need to adjust the mouse position m:1205,989), then I see delays of about 1s only.

AppleScript (to start screen recording) takes 9 to 15s to even start running. Why?

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I'm working on macOS 10.15.6 (Catalina)

AppleScript (to start screen recording) takes 6 to 12s to even start running. Why?

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 6s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 12s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I'm working on macOS 10.15.6 (Catalina)

Update

I did some more tests and it really seems to be the AppleScript that slows things down. If I install the command-line tool cliclick and assign cliclick kd:cmd,shift t:5 m:1205,989 kp:enter to a Quick-Action-based keystroke (which mimics the clicking sequence to start screen recording; you might need to adjust the mouse position m:1205,989), then I see delays of about 1s only.

added 43 characters in body
Source Link
mathlete
  • 162
  • 1
  • 8

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I'm working on macOS 10.15.6 (Catalina)

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell

I'm working on macOS 10.15.6 (Catalina)

Source Link
mathlete
  • 162
  • 1
  • 8

AppleScript (to start screen recording) takes 9 to 15s to even start running. Why?

I use the following AppleScript (assigned to keystroke Cmd+Ctrl+5) to start screen recordings (adapted from here). If I create an Automator Quick Action and assign the keystroke to it, it takes 9s until the screen recording starts. If I call the script via osascript ./screenrecord_starter.scpt from the command line, it takes about 15s. Why does it take so long (and how can this be improved [either by how the script is called or by the script itself])?

#!/usr/bin/osascript

--  Setup screen recording (mimics 'Cmd-S-5')
tell application "System Events" to keystroke "%" using {shift down, command down}

--  Start the screen recording
tell application "System Events" to tell process "Screen Shot"
    repeat until exists its front window
        delay 0.1
    end repeat
    if not (exists button "Record" of its front window) then
        click checkbox "Record Entire Screen" of its front window
    end if
    click button "Record" of its front window
end tell