Skip to content

Instantly share code, notes, and snippets.



Last active Jun 19, 2021
What would you like to do?
Luxafor Spotify integration

Luxafor <-> Spotify integration

This set of scripts will change your Luxafor light's colors based on your Spotify player's state. It polls every 10 seconds for Spotify's play state and changes the color accordingly (playing -> red, not playing -> green).

The script will record what color it set on the last run and will not set it again if it does not change. This way you can manually override the setting and the script won't fight you before changing play states again.


  • Checkout the files (I've used ~/Code/luxafor_toggle) and npm install
  • Copy the to ~/bin and make sure it's executable. Make sure it points to an existing node executable and where you copied the gist repo.
  • Open the .scpt file with AppleScript editor and make sure it points to the .sh file.
  • Make sure the .plist points to where your Apple script file is located. You can change the poll interval (default 10s) by changing the StartInterval value.
  • Link the .plist file to ~/Library/LaunchAgents/
  • Start it by running launchctl load -w ~/Library/LaunchAgents/fi.mumakil.luxafor_spotify.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
"name": "luxafor_toggle",
"version": "0.0.1",
"description": "Toggle luxafor from commandline",
"main": "toggle.js",
"dependencies": {
"luxafor-api": "^2.0.0"
"devDependencies": {
"eslint": "^3.5.0"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"author": "Otto Vehviläinen <>",
"license": "ISC"
const Luxafor = require('luxafor-api');
const fs = require('fs');
const STATEFILE = __dirname + '/STATE';
function loadCurrentState() {
try {
return fs.readFileSync(STATEFILE, {encoding: 'utf8'}).trim();
} catch (e) {
return null;
function writeCurrentState(newState) {
try {
fs.writeFileSync(STATEFILE, newState, {encoding: 'utf8'});
} catch (e) {
// probably can't do anything here?
const device = new Luxafor();
const color = (process.argv[2] || '').trim();
const currentState = loadCurrentState();
if (currentState && currentState === color) {
if (color === 'green') {
} else if (color === 'red') {
#!/usr/bin/env bash
/Users/otto/.nvm/versions/node/v6.6.0/bin/node ~/Code/luxafor_toggle/toggle.js "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment