Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created December 30, 2020 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtetsuji/cd38378c4d1534bd82c3d9a3d3b30fd9 to your computer and use it in GitHub Desktop.
Save xtetsuji/cd38378c4d1534bd82c3d9a3d3b30fd9 to your computer and use it in GitHub Desktop.
Simple music files importer for Apple macOS new Music.app
#!/usr/bin/osascript -l JavaScript
function run(argv) {
const music = Application("Music");
for ( const file of argv ) {
console.log(`add: "${file}"`);
music.add(file);
}
}
#!/bin/bash
set -eu
MUSIC_PATH_RE=".*\.(m4a|m4p)$"
MUSIC_ADD_CMD=add-music.js
declare DEBUG
function main {
dir=${1:-}
if [ ! -d "$dir" ] ; then
echo "1st argument is required as directory that (descent) contains music files."
echo "Usage: $0 DIRECTORY_MUSIC_CONTAINS"
exit 1
fi
shift
local STDIN_MUSIC_ADD_CMD
if [ -n "$DEBUG" ] ; then
echo "DEBUG MODE, DUMP ONLY"
STDIN_MUSIC_ADD_CMD="perl -0lnE say"
else
STDIN_MUSIC_ADD_CMD="xargs -0 $MUSIC_ADD_CMD"
fi
find -E "$dir" -type f -iregex "$MUSIC_PATH_RE" \
| perl -pe 's{^(?!/)}{$ENV{PWD}/}' \
| perl -pe 's/\n/\x00/' \
| $STDIN_MUSIC_ADD_CMD
#| xargs -0 $MUSIC_ADD_CMD
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment