Created
December 30, 2020 11:03
-
-
Save xtetsuji/cd38378c4d1534bd82c3d9a3d3b30fd9 to your computer and use it in GitHub Desktop.
Simple music files importer for Apple macOS new Music.app
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 | |
function run(argv) { | |
const music = Application("Music"); | |
for ( const file of argv ) { | |
console.log(`add: "${file}"`); | |
music.add(file); | |
} | |
} |
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
#!/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