Last active
August 29, 2015 14:21
-
-
Save tylerball/62e2d072dce0da725fd4 to your computer and use it in GitHub Desktop.
my old ipod doesn't do album artists, here's a JXA script to move featured artists to the track names: http://tylerball.net/articles/2015/05/fixing-album-artist-on-an-ipod-classic/
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
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
var iTunes = Application('iTunes') | |
var selection = [].slice.call(iTunes.selection()) | |
var featured = 'ft.' | |
var search = prompt('Enter delimiter to search for (RegExp):', '(.*)feat\\\.(.*)') | |
var errors = []; | |
selection.forEach(function(track) { | |
var artist = track.artist(); | |
var name = track.name(); | |
var result = new RegExp(search, 'gi').exec(artist); | |
try { | |
if (result && result.length) { | |
var newName = name + ' ' + featured + ' ' + result[2].trim(); | |
track.artist = result[1].trim(); | |
track.name = newName; | |
} | |
} catch (e) { | |
errors.push(e) | |
} | |
}); | |
function prompt(text, defaultAnswer) { | |
var options = { defaultAnswer: defaultAnswer || '' } | |
try { | |
return app.displayDialog(text, options).textReturned | |
} catch (e) { | |
return null | |
} | |
} | |
function alert(text, informationalText) { | |
var options = { } | |
if (informationalText) options.message = informationalText | |
app.displayAlert(text, options) | |
} | |
if (errors.length) { | |
errs = errors.reduce(function (p, c) { p + String(c) + '\n' }, ''); | |
console.log(errs); | |
alert('Errors:', errs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment