Created
March 20, 2025 00:55
-
-
Save androidStern/a17a4f0c81a9175c67baec64b11e93d0 to your computer and use it in GitHub Desktop.
Script to test adding a device from the browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Ableton } from 'ableton-js' | |
| import { execSync } from 'child_process' | |
| process.env.TMPDIR = execSync('getconf DARWIN_USER_TEMP_DIR').toString().trim() | |
| const logger = { | |
| debug: (msg, ...args) => console.error(`[DEBUG] ${msg}`, ...args), | |
| info: (msg, ...args) => console.error(`[INFO] ${msg}`, ...args), | |
| warn: (msg, ...args) => console.error(`[WARN] ${msg}`, ...args), | |
| error: (msg, ...args) => console.error(`[ERROR] ${msg}`, ...args), | |
| log: (msg, ...args) => console.error(`[LOG] ${msg}`, ...args) | |
| } | |
| async function main() { | |
| const ableton = new Ableton({ logger }) | |
| logger.info('Connecting to Ableton...') | |
| const exitTimeout = setTimeout(() => { | |
| logger.error('Script timed out after 10 seconds, forcing exit') | |
| process.exit(1) | |
| }, 10000) | |
| try { | |
| await ableton.start(5000) | |
| const browser = ableton.application.browser | |
| const instruments = await browser.get('instruments') | |
| logger.info(`Found ${instruments.length} instrument categories`) | |
| instruments.forEach((item, i) => { | |
| logger.info( | |
| `Instrument Category ${i + 1}: ${item.raw.name} (loadable: ${item.raw.is_loadable})` | |
| ) | |
| }) | |
| const loadableCategory = instruments.find(item => item.raw.is_loadable) | |
| if (loadableCategory) { | |
| logger.info(`Loading instrument: ${loadableCategory.raw.name}`) | |
| await browser.sendCommand('load_item', { id: loadableCategory.raw.id }) | |
| logger.info('Instrument loaded successfully') | |
| } else { | |
| logger.info('No loadable instruments found') | |
| } | |
| } catch (error) { | |
| logger.error('Error:', error) | |
| } finally { | |
| clearTimeout(exitTimeout) | |
| logger.info('Cleaning up and exiting...') | |
| try { | |
| if (ableton.client) { | |
| ableton.client.close() | |
| } | |
| } catch (e) { | |
| logger.error('Error closing client:', e) | |
| } | |
| setTimeout(() => process.exit(0), 500) | |
| } | |
| } | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment