Getting Started

Scripts are plain .js files placed in your scripts folder:

~/Library/Application Support/OrangeMusicPlayer/Scripts/

Open the folder from the menu bar: Scripts → Open Scripts Folder. Orange detects new and changed scripts automatically — no restart needed.

To run an on-demand script, use the Scripts menu or the Scripts panel in the sidebar. Event-driven scripts run automatically when their trigger fires.

Script Metadata

Add a comment block at the top of your script to declare metadata:

// @name       My Script
// @description What it does
// @author     Your Name
// @event      trackChanged
TagRequiredDescription
@nameNoDisplay name. Falls back to the filename.
@descriptionNoShort description shown in the Scripts panel.
@authorNoAuthor name.
@eventNoEvent name to auto-run on. Omit for on-demand scripts.

Console

Use console.log(), console.warn(), and console.error() to send output to the Script Console. Open it with Scripts → Script Console or Cmd+Shift+J.

console.log('Hello', 'world');    // supports multiple arguments
console.warn('Heads up!');
console.error('Something broke');

orange.player

Control playback and read the current player state.

Methods

orange.player.play()

Start or resume playback.

orange.player.pause()

Pause playback.

orange.player.stop()

Stop playback and reset position.

orange.player.next()

Skip to the next track in the queue.

orange.player.previous()

Go back to the previous track.

orange.player.seek(seconds)

Seek to a position in the current track (in seconds).

Properties

PropertyTypeDescription
orange.player.currentTrackTrack | nullThe currently playing track object.
orange.player.positionNumberCurrent playback position in seconds.
orange.player.isPlayingBooleantrue if audio is currently playing.
orange.player.volumeNumberVolume level (0.0 – 1.0). Read/write.
var track = orange.player.currentTrack;
if (track) {
    console.log(track.title + ' by ' + track.artist);
    console.log('Position: ' + orange.player.position + 's');
}

// Set volume to 80%
orange.player.volume = 0.8;

orange.library

Search and retrieve tracks, albums, and artists from your library.

orange.library.searchTracks(query) → Track[]

Search tracks by title, artist, or album. Pass an empty string to get all tracks.

orange.library.searchAlbums(query) → Album[]

Search albums by title or artist.

orange.library.searchArtists(query) → Artist[]

Search artists by name.

orange.library.getTrack(id) → Track | null

Get a single track by its ID.

orange.library.getAlbum(id) → Album | null

Get a single album by its ID.

orange.playlists

Create, delete, and manage playlists.

orange.playlists.list() → Playlist[]

Get all playlists.

orange.playlists.create(name)

Create a new playlist with the given name.

orange.playlists.delete(playlistId)

Delete a playlist by its ID.

orange.playlists.addTrack(playlistId, trackId)

Add a track to a playlist.

orange.playlists.removeTrack(playlistId, trackId)

Remove a track from a playlist.

orange.playlists.getTracks(playlistId) → Track[]

Get all tracks in a playlist.

orange.effects

Inspect and control the audio effects chain (EQ, reverb, AU plugins).

orange.effects.chain() → Slot[]

Returns an array of effect slots. Each slot has type, name, manufacturer, and isBypassed. Empty slots are null.

orange.effects.bypass(slotIndex, bypassed)

Enable or bypass an effect slot.

orange.effects.setParameter(slotIndex, paramAddress, value)

Set a parameter value on an AU plugin by address.

orange.effects.getParameter(slotIndex, paramAddress) → Number

Get the current value of an AU parameter.

orange.effects.loadPreset(slotIndex, preset, source)

Load a factory preset by number or name. source must be "factory".

var slots = orange.effects.chain();
for (var i = 0; i < slots.length; i++) {
    if (slots[i]) {
        console.log(slots[i].name + ' — bypassed: ' + slots[i].isBypassed);
    }
}

// Bypass the first effect
orange.effects.bypass(0, true);

// Load factory preset #0 on slot 1
orange.effects.loadPreset(1, 0, 'factory');

Events

Register callbacks for playback and library events using orange.on().

orange.on(eventName, callback)

Register an event handler. Multiple handlers per event are supported.

EventCallback ArgumentFires When
trackChangedTrack objectA new track starts playing.
playbackStartedPlayback resumes.
playbackPausedPlayback is paused.
playbackStoppedPlayback stops.
queueChangedThe playback queue is modified.
libraryUpdatedThe library is rescanned.
orange.on('trackChanged', function(track) {
    console.log('Now playing: ' + track.title);
});

orange.on('playbackPaused', function() {
    console.log('Paused');
});

To bind an event-driven script, add @event in the metadata header. The script will automatically run when that event fires, and your orange.on() handlers will be called.

Track Object

Track objects returned by the API have these properties:

PropertyTypeNotes
idNumberUnique database ID.
titleStringTrack title.
artistStringMay be absent.
albumStringMay be absent.
genreStringMay be absent.
durationNumberDuration in seconds.
trackNumberNumberMay be absent.
yearNumberMay be absent.
playCountNumberNumber of times played.
ratingNumber1–5 stars. May be absent.
isFavoriteBooleanWhether the track is favorited.
filePathStringAbsolute file path.

Album objects have: id, title, artist, year, trackCount.
Artist objects have: id, name, albumCount, trackCount.
Playlist objects have: id, name, trackCount.

Examples

Favorites Playlist Builder

On-Demand
// @name       Quick Favorites Playlist
// @description Collects all favorited tracks into a new playlist
// @author     Orange Music Player

var allTracks = orange.library.searchTracks('');
var favorites = [];

for (var i = 0; i < allTracks.length; i++) {
    if (allTracks[i].isFavorite) {
        favorites.push(allTracks[i]);
    }
}

console.log('Found ' + favorites.length + ' favorite tracks');

if (favorites.length > 0) {
    orange.playlists.create('My Favorites (Script)');

    // Find the newly created playlist
    var playlists = orange.playlists.list();
    var target = null;
    for (var j = 0; j < playlists.length; j++) {
        if (playlists[j].name === 'My Favorites (Script)') {
            target = playlists[j];
        }
    }

    if (target) {
        for (var k = 0; k < favorites.length; k++) {
            orange.playlists.addTrack(target.id, favorites[k].id);
        }
        console.log('Added ' + favorites.length + ' tracks to playlist');
    }
}

Run this from the Scripts menu. It scans your entire library for favorited tracks and creates a playlist containing them all.

Genre Logger

Event-Driven
// @name       Genre Logger
// @description Logs genre info every time the track changes
// @author     Orange Music Player
// @event      trackChanged

orange.on('trackChanged', function(track) {
    if (!track) return;

    var genre = track.genre || 'Unknown';
    console.log(track.title + ' [' + genre + '] by ' + (track.artist || 'Unknown'));

    // Detect jazz and log something fun
    if (genre.toLowerCase().indexOf('jazz') !== -1) {
        console.log('Jazz detected! Smooth listening ahead.');
    }
});

This script runs automatically every time a new track starts playing. It logs the genre to the Script Console, with a special message for jazz tracks. Use Cmd+Shift+J to open the console and watch the output.

Top Played Playlist

On-Demand
// @name       Top 20 Most Played
// @description Creates a playlist from your 20 most-played tracks
// @author     Orange Music Player

var all = orange.library.searchTracks('');

// Sort by play count descending
all.sort(function(a, b) { return b.playCount - a.playCount; });

var top = all.slice(0, 20);
console.log('Top track: ' + top[0].title + ' (' + top[0].playCount + ' plays)');

orange.playlists.create('Top 20 Most Played');

var playlists = orange.playlists.list();
var target = null;
for (var i = 0; i < playlists.length; i++) {
    if (playlists[i].name === 'Top 20 Most Played') {
        target = playlists[i];
    }
}

if (target) {
    for (var i = 0; i < top.length; i++) {
        orange.playlists.addTrack(target.id, top[i].id);
    }
    console.log('Created playlist with ' + top.length + ' tracks');
}

Sorts your entire library by play count and builds a playlist of your 20 most-listened tracks. Run it periodically to keep an up-to-date "heavy rotation" list.