Created
March 27, 2025 13:10
-
-
Save n8henrie/d2d14c9d58f85d7499ab8e40e468d758 to your computer and use it in GitHub Desktop.
Export playlists from Music.app to all available formats
This file contains 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
#!/usr/bin/osascript -l JavaScript | |
'use strict' | |
ObjC.import("Foundation") | |
const environment = $.NSProcessInfo.processInfo.environment.js | |
const DEST = Path(environment.HOME.js + "/Music") | |
function run(_) { | |
let music = Application("Music") | |
let formats = { | |
"Unicode text": "txt", | |
"XML": "xml", | |
"M3U": "m3u", | |
"M3U8": "m3u8", | |
} | |
let finder = Application("Finder") | |
let timestamp = new Date().toISOString().replace(/[:.-]/g, "").replace(/Z$/, "") | |
let playlists = Path(`${DEST}/playlists`) | |
if (!finder.exists(playlists)) { | |
finder.make({ | |
new: "folder", | |
at: DEST, | |
withProperties: { name: "playlists" }, | |
}) | |
} | |
let fullpath = Path(`${playlists}/${timestamp}`) | |
if (!finder.exists(fullpath)) { | |
finder.make({ | |
new: "folder", | |
at: playlists, | |
withProperties: { name: timestamp }, | |
}) | |
} | |
music.playlists().forEach(pl => { | |
let name = pl.name() | |
// For whatever reason it errors on this playlist in my case | |
if (name == "Favorite Songs") { | |
return | |
} | |
Object.entries(formats).forEach(([fmt, ext]) => { | |
let file = `${fullpath}/${name}.${ext}` | |
console.log(`exporting ${name} to ${file}`) | |
pl.export({as: fmt, to: file}) | |
}) | |
}) | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment