Skip to content

Latest commit

 

History

History
79 lines (59 loc) · 2.66 KB

README.md

File metadata and controls

79 lines (59 loc) · 2.66 KB

QuartzGetWindow.jl

CI

Description

Application

You can record an active window during the calculation.

using Dates
using QuartzGetWindow

struct ScreenRecorder
    procref::Ref{Base.Process}
end

function ScreenRecorder(proc::Base.Process)
    ScreenRecorder(Ref(proc))
end

function start(::Type{ScreenRecorder})
    n = getActiveWindowName()
    @debug n
    x, y, w, h = getWindowGeometry(n)
    file = "$(Dates.now()).mov"

    inp = Base.PipeEndpoint()
    out = Base.PipeEndpoint()
    err = Base.PipeEndpoint()
    # Run `screencapture` command
    cmd = `screencapture -R$(x),$(y),$(w),$(h) -v $(file)`
    proc = Base.run(cmd, inp, out, err, wait = false)
    recorder = ScreenRecorder(proc)
    return recorder
end

function quit(recorder::ScreenRecorder)
    # press q key
    write(recorder.procref[], "q")
end

function main()
    @debug "Start recording..."
    sleep(1.0)
    recorder = start(ScreenRecorder)
    # Do something
    sleep(1.0)
    println("Count down")
    for i = 5:-1:1
        println("i=$(i)")
        sleep(0.5)
    end
    println("🚀")
    # Stop `screencapture` process
    quit(recorder)
    @debug "Quit"
    exit()
end

main()

You will get the following result:

2024-12-18T16.27.00.633.mov

Known issue

Somethimes, getActiveWindowName() gets an unexpected result on Apple M-series. Restarting your macOS device may solve this issue, but I can't figure out why it happens.