Skip to content

Commit f155fa9

Browse files
committed
feat(screen-recording): add screen recording and measurement API
Add new SDK exports for screen recording functionality: - screenRecord() for capturing screen recordings with options - measure() for interactive screen area measurement - Add channels for screen recording control (start, stop, pause, resume) - Add MEASURE channels for measurement overlay - Add screenRecorder UI type - Add Meta key aliases for cross-platform support
1 parent 53d8ab7 commit f155fa9

3 files changed

Lines changed: 187 additions & 2 deletions

File tree

src/core/enum.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ export enum Channel {
366366
OPEN_ACTIONS = 'OPEN_ACTIONS',
367367
KEYBOARD_TYPE_RATE = 'KEYBOARD_TYPE_RATE',
368368
SCREENSHOT = 'SCREENSHOT',
369+
MEASURE = 'MEASURE',
370+
MEASURE_COMPLETE = 'MEASURE_COMPLETE',
371+
MEASURE_CANCELLED = 'MEASURE_CANCELLED',
369372
SCRIPT_CHANGED = 'SCRIPT_CHANGED',
370373
SCRIPT_ADDED = 'SCRIPT_ADDED',
371374
SCRIPT_REMOVED = 'SCRIPT_REMOVED',
@@ -377,7 +380,17 @@ export enum Channel {
377380
TERMINATE_PROMPT = 'TERMINATE_PROMPT',
378381
CLEANUP_PROMPTS = 'CLEANUP_PROMPTS',
379382
GET_PROMPT_STATUS = 'GET_PROMPT_STATUS',
380-
FORCE_PROMPT_CLEANUP = 'FORCE_PROMPT_CLEANUP'
383+
FORCE_PROMPT_CLEANUP = 'FORCE_PROMPT_CLEANUP',
384+
// Screen Recording Channels
385+
START_SCREEN_RECORDING = 'START_SCREEN_RECORDING',
386+
STOP_SCREEN_RECORDING = 'STOP_SCREEN_RECORDING',
387+
PAUSE_SCREEN_RECORDING = 'PAUSE_SCREEN_RECORDING',
388+
RESUME_SCREEN_RECORDING = 'RESUME_SCREEN_RECORDING',
389+
SCREEN_AREA_SELECTED = 'SCREEN_AREA_SELECTED',
390+
GET_SCREEN_SOURCES = 'GET_SCREEN_SOURCES',
391+
SHOW_AREA_SELECTOR = 'SHOW_AREA_SELECTOR',
392+
SCREEN_RECORDING_STATUS = 'SCREEN_RECORDING_STATUS',
393+
SCREEN_RECORDING_STREAM = 'SCREEN_RECORDING_STREAM'
381394
}
382395

383396
export enum ProcessType {
@@ -420,7 +433,8 @@ export enum UI {
420433
debugger = 'debugger',
421434
chat = 'chat',
422435
mic = 'mic',
423-
webcam = 'webcam'
436+
webcam = 'webcam',
437+
screenRecorder = 'screenRecorder'
424438
}
425439

426440
export enum Bin {
@@ -450,6 +464,10 @@ export enum Key {
450464
LeftSuper = 'command',
451465
RightShift = 'right_shift',
452466
RightSuper = 'command',
467+
// Cross-platform aliases for the "super" key (Command on macOS, Windows key on Windows, Meta on Linux)
468+
Meta = 'command',
469+
LeftMeta = 'command',
470+
RightMeta = 'command',
453471
F1 = 'f1',
454472
F2 = 'f2',
455473
F3 = 'f3',

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (!process?.env?.KIT_TARGET) {
2222

2323
export * from "./api/kit.js"
2424
export * from "./core/utils.js"
25+
export * from "./screenRecording.js"
2526

2627

2728
let dirs = ["cli", "main"]

src/screenRecording.ts

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/**
2+
* Screen Recording API for Script Kit
3+
* Enables screen capture with optional area selection
4+
*
5+
* These functions are available globally in scripts.
6+
* This module re-exports them for explicit imports if needed.
7+
*/
8+
9+
/**
10+
* Screen source available for recording
11+
*/
12+
export interface ScreenSource {
13+
id: string
14+
name: string
15+
thumbnail: string
16+
displayId: string
17+
}
18+
19+
/**
20+
* Area definition for recording a portion of the screen
21+
*/
22+
export interface RecordingArea {
23+
x: number
24+
y: number
25+
width: number
26+
height: number
27+
displayId?: number
28+
}
29+
30+
/**
31+
* Result returned from a screen recording operation
32+
*/
33+
export interface ScreenRecordingResult {
34+
filePath: string
35+
duration: number
36+
width: number
37+
height: number
38+
cancelled: boolean
39+
}
40+
41+
/**
42+
* Result returned from a measurement operation
43+
*/
44+
export interface MeasureResult {
45+
x: number
46+
y: number
47+
width: number
48+
height: number
49+
right: number
50+
bottom: number
51+
centerX: number
52+
centerY: number
53+
area: number
54+
displayId?: string
55+
scaleFactor?: number
56+
cancelled: boolean
57+
}
58+
59+
/**
60+
* Configuration options for screen recording
61+
*/
62+
export interface ScreenRecordOptions {
63+
/** Video format: 'webm' or 'mp4' (default: 'webm') */
64+
format?: 'webm' | 'mp4'
65+
/** Video quality 0.0-1.0 (default: 0.9) */
66+
quality?: number
67+
/** Frame rate in FPS (default: 30) */
68+
frameRate?: number
69+
/** Include system audio (default: false) */
70+
includeAudio?: boolean
71+
/** Whether to prompt for area selection (default: false for full screen) */
72+
selectArea?: boolean
73+
/** Pre-defined area to record (skips area selection) */
74+
area?: RecordingArea
75+
/** Specific source ID to record (skips source selection) */
76+
sourceId?: string
77+
/** Custom file path for the recording (default: temp directory) */
78+
filePath?: string
79+
/** Maximum recording duration in seconds (0 = unlimited) */
80+
maxDuration?: number
81+
/** Instructions shown to the user during area selection */
82+
hint?: string
83+
/** Whether to show recording controls overlay (default: true) */
84+
showControls?: boolean
85+
/** Whether to show countdown before recording starts (default: true) */
86+
countdown?: boolean
87+
/** Countdown duration in seconds (default: 3) */
88+
countdownSeconds?: number
89+
}
90+
91+
/**
92+
* Configuration options for the measurement tool
93+
*/
94+
export interface MeasureOptions {
95+
/** Stroke color for the selection rectangle (default: #00ff00) */
96+
color?: string
97+
/** Width of the selection border in pixels (default: 2) */
98+
strokeWidth?: number
99+
/** Opacity of the selection fill (0-1, default: 0.1) */
100+
fillOpacity?: number
101+
/** Whether to show dimension labels (default: true) */
102+
showDimensions?: boolean
103+
/** Whether to show crosshair guides (default: true) */
104+
showCrosshair?: boolean
105+
/** Font size for dimension labels (default: 14) */
106+
fontSize?: number
107+
/** Grid size for snapping, 1 = no snap (default: 1) */
108+
gridSnap?: number
109+
/** Whether to constrain selection to current display (default: false) */
110+
constrainToDisplay?: boolean
111+
/** Whether to allow keyboard adjustments after initial drag (default: true) */
112+
allowKeyboardAdjust?: boolean
113+
/** Instructions shown to the user */
114+
hint?: string
115+
/** Starting position for the overlay (follows cursor if not specified) */
116+
startPosition?: { x: number; y: number }
117+
/** Initial rectangle to display (for editing existing measurement) */
118+
initialRect?: { x: number; y: number; width: number; height: number }
119+
/** Clipboard format when user presses Cmd+C during measurement */
120+
clipboardFormat?: 'dimensions' | 'css' | 'json'
121+
}
122+
123+
/**
124+
* Get available screen sources for recording
125+
* @see global.getScreenSources
126+
*/
127+
export const getScreenSources = (): Promise<ScreenSource[]> => global.getScreenSources()
128+
129+
/**
130+
* Start a screen recording session
131+
* @see global.screenRecord
132+
*/
133+
export const screenRecord = (options?: ScreenRecordOptions): Promise<ScreenRecordingResult | null> =>
134+
global.screenRecord(options)
135+
136+
/**
137+
* Stop an active screen recording
138+
* @see global.stopScreenRecording
139+
*/
140+
export const stopScreenRecording = (): Promise<ScreenRecordingResult | null> =>
141+
global.stopScreenRecording()
142+
143+
/**
144+
* Pause an active screen recording
145+
* @see global.pauseScreenRecording
146+
*/
147+
export const pauseScreenRecording = (): Promise<boolean> => global.pauseScreenRecording()
148+
149+
/**
150+
* Resume a paused screen recording
151+
* @see global.resumeScreenRecording
152+
*/
153+
export const resumeScreenRecording = (): Promise<boolean> => global.resumeScreenRecording()
154+
155+
/**
156+
* Get the current screen recording status
157+
* @see global.getScreenRecordingStatus
158+
*/
159+
export const getScreenRecordingStatus = () => global.getScreenRecordingStatus()
160+
161+
/**
162+
* Opens a transparent overlay for measuring screen areas
163+
* @see global.measure
164+
*/
165+
export const measure = (options?: MeasureOptions): Promise<MeasureResult | null> =>
166+
global.measure(options)

0 commit comments

Comments
 (0)