Record the screen on macOS
- macOS 13+
- Xcode 15+
- Swift 5.7+
Add the following to Package.swift:
.package(url:"https://github.com/wulkano/Aperture", from:"3.0.0")import Foundation
import Aperture
letrecorder=Aperture.Recorder()letscreens=tryawaitAperture.Devices.screen()guardlet screen = screens.first else{
// No screens
exit(1)}tryawait recorder.start(
target:.screen,
options:Aperture.RecordingOptions(
destination:URL(filePath:"./screen-recording.mp4"),
targetID: screen.id,))tryawaitTask.sleep(for:.seconds(5))tryawait recorder.stop()Type: URL
The filepath where the resulting recording should be written to.
Type: String
The ID of the target to record
Type: Bool
Default: false
Will use the lossless ALAC codec if enabled, AAC otherwise.
Type: Bool
Default: false
Record the system audio.
Type: String?
A microphone device ID to record.
Type: Int
Default: 60
Number of frames per seconds.
Type: Bool
Default: true
Show the cursor in the screen recording.
Type: Bool
Default: false
Highlight cursor clicks in the screen recording.
Note: This will only apply on macOS 15+
Type: Aperture.VideoCodec
Default: .h264
Values: .h264, .hevc, .proRes422, .proRes4444
The video codec to be used.
Use Aeprture.Devices.screen to discover the available screens
And then start recording with target: .screen
tryawait recorder.start(
target:.screen,
options:Aperture.RecordingOptions(
destination: fileURL,
targetID: screen.id,
framesPerSecond:60,
cropRect:CGRect(x:10, y:10, width:100, height:100),
showCursor:true,
highlightClicks:true,
videoCodec:.h264,
losslessAudio:true,
recordSystemAudio:true,
microphoneDeviceID: microphone.id,))Accepts all the base video and audio options along with:
Type: CGRect?
Record only an area of the screen.
Use Aeprture.Devices.window to discover the available windows
And then start recording with target: .window
tryawait recorder.start(
target:.window,
options:Aperture.RecordingOptions(
destination: fileURL,
targetID: window.id,
framesPerSecond:60,
showCursor:true,
highlightClicks:true,
videoCodec:.h264,
losslessAudio:true,
recordSystemAudio:true,
microphoneDeviceID: microphone.id,))Accepts all the base video and audio options
Use Aeprture.Devices.audio to discover the available audio devices
And then start recording with target: .audioOnly
tryawait recorder.start(
target:.audioOnly,
options:Aperture.RecordingOptions(
destination: fileURL,
losslessAudio:true,
recordSystemAudio:true,
microphoneDeviceID: microphone.id,))Accepts all the base audio options.
Use Aeprture.Devices.iOS to discover the available external devices
And then start recording with target: .externalDevice
tryawait recorder.start(
target:.externalDevice,
options:Aperture.RecordingOptions(
destination: fileURL,
targetID: device.id,
framesPerSecond:60,
videoCodec:.h264,
losslessAudio:true,
recordSystemAudio:true,
microphoneDeviceID: microphone.id,))Accepts the base video options except for cursor related ones, and all the audio options.
letscreens=tryawaitAperture.Devices.screen()letwindows=tryawaitAperture.Devices.window(excludeDesktopWindows:true, onScreenWindowsOnly:true)Type: Bool
Default: true
Type: Bool
Default: true
letdevices=Aperture.Devices.audio()letdevices=Aperture.Devices.iOS()Run ./example.sh or ./example-ios.sh.
- aperture-node - Node.js wrapper