Motion
Get Motion

ReferenceScripting APIMotionScene

MotionScene

interface

The scene: everything a script can do.

NameMotionScene
Kindinterface
Script reaches it asscene (a global), or import scene from "motion"
Since0.3

Syntax

interface MotionScene { … }declare const scene: MotionScene;

Sound

Properties

NameTypeDescription
audiopropertyreadonly MotionAudioWhat's playing, 0 to 1 each, when the computer listens.
beatpropertyreadonly MotionBeatThe beat of what's playing.
spectrumpropertyreadonly number[]The sound's 64 bands, low to high (35 Hz to 10 kHz), 0 to 1 each.
waveformpropertyreadonly number[]The sound's shape: 64 samples, -1 to 1.

Methods

SignatureDescription
loadSound(file: string, options?: { bus?: string }): MotionSoundmethodLoads a sound file of the scene's folder, decoded as the scene opens.
sound(name: string): MotionSoundLayermethodA Sound layer, by its name or id.
band(lowHz: number, highHz: number): numbermethodHow loud a band of pitches is, from the spectrum.

Web

Methods

SignatureDescription
sendToPage(layer: string, data: unknown): voidmethodSends something to a web project's page (its motion.on("message")).
fetch(url: string, options?: { method?: "GET" | "POST" | "HEAD"; headers?: Record<string, string>; body?: unknown }): Promise<MotionFetched>methodReads a web address on one of the sites the scene may read (Websites it may read, on the Scene's Script card), when the person allows it.
prop<T>(id: string): TmethodOne of the wallpaper's own settings.

Layers

Properties

NameTypeDescription
layerspropertyreadonly MotionLayerInfo[]All of the scene's layers, bottom first: each one's id, name, kind and folder.
folderspropertyreadonly ({ id: string; name: string; layers: string[] })[]The scene's folders: each its id, name and the layers in it.
widthpropertyreadonly numberThe scene's width, pixels.
heightpropertyreadonly numberThe scene's height, pixels.

Methods

SignatureDescription
set(layer: string, setting: string, value: SettingValue): voidmethodChanges one of a layer's settings at once. The value is kept in the setting's range.
animate(layer: string, setting: string, value: string | number, seconds: number, options?: MotionAnimateOptions): Promise<boolean>methodMoves a number or a colour setting to a new value smoothly, over some seconds.
stopAnimating(layer: string, setting?: string): voidmethodStops a layer's moves where they are now.
get(layer: string, setting: string): SettingValue | undefinedmethodA setting's value: what the script last set, or else what the scene started with. Not what keyframes, the sound or a move make it: see read.
read(layer: string, setting: string): SettingValue | undefinedmethodA setting as it was last drawn: its keyframes, the sound and moves in.
show(layer: string, visible: boolean): voidmethodShows or hides a layer.
hide(layer: string): voidmethodHides a layer.
layer(name: string): MotionLayermethodOne layer, to change without naming it each time.
layersNamed(name: string): MotionLayerInfo[]methodEvery layer with a name, bottom first (a name can be shared; ids can't).
layerAt(x: number, y: number): MotionLayerInfo | nullmethodThe top layer drawn at a point.
bringToFront(layer: string): voidmethodMoves a layer above the others beside it.
sendToBack(layer: string): voidmethodMoves a layer below the others beside it.
clone(layer: string, name?: string): MotionLayermethodA copy of a layer, just above it, while the scene plays.
remove(layer: string): voidmethodTakes a layer out of the scene while it plays (the scene's file is as it was).

Text

Methods

SignatureDescription
text(layer: string, words: string): voidmethodChanges what a Text layer says.
setVar(name: string, value: unknown): voidmethodFills {name} in every Text layer, so one layer can say "It's {temp} outside".

Particles

Methods

SignatureDescription
particles(layer: string): MotionParticlesmethodA particle layer's system: bursts, rates, pausing.

Video

Methods

SignatureDescription
video(layer: string): MotionVideomethodA Video layer's film: play, hold, seek and speed it.

3D

Methods

SignatureDescription
camera(layer: string): MotionCameramethodA 3D layer's camera.
pickItem(layer: string, x: number, y: number): Promise<{ item: number; mote: Mote | null } | null>methodWhich of a 3D layer's items is under a point, as last drawn.

Time

Properties

NameTypeDescription
timepropertyreadonly numberHow long the scene has been playing, seconds.
pausedpropertyreadonly booleanWhether the wallpaper is paused just now (covered by a window, on battery, or by hand).
qualitypropertyreadonly numberHow finely the wallpaper is drawn, 0 to 1: lower on battery or a slow computer.
tickRatepropertynumberTicks a second the script hears (scene.on("tick"), timers); 0, the default, is every frame. Set it to tick less often.
clockpropertyreadonly MotionClockThe clock where the desktop is.

Methods

SignatureDescription
every(seconds: number, fn: () => void): numbermethodRuns a function again and again, every so many seconds.
after(seconds: number, fn: () => void): numbermethodRuns a function once, after some seconds.
cancel(id: number): voidmethodStops something scene.every or scene.after would run.

Events

Methods

SignatureDescription
on<E extends keyof MotionEvents>(event: E, fn: MotionEvents[E], options?: MotionEventOptions): () => voidmethodListens for something happening.
off<E extends keyof MotionEvents>(event: E, fn: MotionEvents[E]): voidmethodStops listening.

Sensors

Methods

SignatureDescription
sensor(name: string): { value: any; at: number } | nullmethodThe latest reading of one of the scene's sensors (those its Sensors tab lists).
onSensor<T>(name: string, fn: (value: T, at: number) => void): () => voidmethodListens for one of the scene's sensors' readings.
sensorAge(name: string): number | nullmethodHow long since one of the scene's sensors' last reading.
sensors(): ({ sensor: string; share: string })[]methodThe sensors the scene listens to, as its Sensors tab lists them.

Numbers and colours

Properties

NameTypeDescription
mathspropertyreadonly MotionMathsMaths for code: noise, easing, smooth steps, ranges.
colourpropertyreadonly MotionColourColour for code: lighter, more colourful, opposite, from a temperature.

Methods

SignatureDescription
random(min?: number, max?: number): numbermethodA random number: 0 to 1, 0 to max, or min to max.
seed(n: number): voidmethodMakes random numbers repeat: the same seed, the same numbers.
pick<T>(list: readonly T[]): T | undefinedmethodA random one of a list.
lerp(a: number, b: number, t: number): numbermethodBetween a and b, t of the way.
clamp(v: number, lo: number, hi: number): numbermethodA number kept within lo and hi.
mix(a: string, b: string, t: number): stringmethodBetween two colours, t of the way.
hsv(h: number, s: number, v: number): stringmethodA colour from its hue, saturation and value.

Memory

Properties

NameTypeDescription
storepropertyreadonly MotionStoreWhat the script keeps between runs (the scene's own).

Methods

SignatureDescription
storeFor(scope: "scene" | "screen"): MotionStoremethodA store of a scope: the scene's own ("scene"), or this screen's ("screen": each screen of several keeps its own).

The console

Methods

SignatureDescription
log(...what: unknown[]): voidmethodWrites to the console.
warn(...what: unknown[]): voidmethodWrites a warning to the console.
error(...what: unknown[]): voidmethodWrites an error to the console.
plugin(...what: unknown[]): voidmethodDoes nothing: plugins aren't available yet.

Environment

Properties

NameTypeDescription
fpspropertyreadonly numberFrames a second the wallpaper is drawn at now (smoothed): lower on battery, or when it's busy.
isPreviewpropertyreadonly booleanWhether it's playing in Studio's preview rather than on the desktop.
platformpropertyreadonly "windows" | "linux" | "android"What it runs on: "windows", "linux" or "android".
localepropertyreadonly stringThe person's language, as a tag: "en-GB", "de-DE"...
screenpropertyreadonly { index: number; count: number; dpr: number }Which screen this is (0 the first), of how many, and its pixels to a point.

Pointer

Properties

NameTypeDescription
capturedpropertyreadonly booleanWhether the scene has the keyboard and pointer (the person gave them: requestInput).
pointerpropertyreadonly MotionPointerThe pointer over the wallpaper.

Methods

SignatureDescription
requestInput(): voidmethodAsks for the keyboard and pointer, as a game layer does: the person gives them with a click on the scene's Play, and key and pad are heard while it has them.
releaseInput(): voidmethodGives the keyboard and pointer back.

World

Properties

NameTypeDescription
weatherpropertyreadonly MotionWeather | nullThe desktop's weather, or null until it says.
mediapropertyreadonly MotionMedia | nullWhat's playing on the desktop: the track, its artist and album, its cover, where it is.
calendarpropertyreadonly { events: MotionEvent[] } | nullThe next days' calendar events (the desktop's own calendar, or the folder of .ics files picked in Motion's settings).
systempropertyreadonly MotionSystem | nullThe computer's load: processor, memory, disk, temperature, network, battery.

Methods

SignatureDescription
weatherAt(place: string | MotionPlace): MotionWeather | nullmethodThe weather at a place the scene names itself: a Weather layer's Place, or a setting that follows the weather at a place of its own.
mediaPosition(): numbermethodWhere what's playing is now, seconds: from what the desktop last said, on since while it plays.

Timeline

Properties

NameTypeDescription
timelinepropertyreadonly MotionTimelineThe keyframes' clock: play, hold, seek and speed them.

See also

MotionSound · MotionSoundLayer · SettingValue · MotionLayer · MotionLayerInfo · MotionParticles · MotionVideo · MotionCamera