Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Forked from mroth/git-music.sh
Last active January 25, 2017 17:54
Show Gist options
  • Save nsfmc/76d0bce821649bb656b6afd57378f8cd to your computer and use it in GitHub Desktop.
Save nsfmc/76d0bce821649bb656b6afd57378f8cd to your computer and use it in GitHub Desktop.
Adds the currently playing iTunes/Spotify track to your prepared git commit message.
#!/bin/bash
# Adds the currently playing iTunes track to your prepared commit message.
#
# To install, save in repo as chmod +x to .git/hooks/prepare-commit-msg
# save music.js somewhere like ~/.bin
# if you don't use a commit template $SONG should precede $1 to allow --verbose
# commits to work, otherwise change the echo to "$(cat $1)\n\n$SONG"
SONG=`osascript -l JavaScript ~/.bin/music.js`
if [[ $SONG ]]; then
echo -e "\n\n$SONG\n$(cat $1)" > $1
fi
#!/usr/bin/env osascript -l JavaScript
var trackForPlayer = (appName) => {
if (Application(appName).running()) {
var player = Application(appName)
if (player.playerState() === 'playing') {
var track = player.currentTrack()
return `♬ : ${track.artist()} / ${track.name()}`
}
}
}
function run(args) {
var currentTrack = trackForPlayer('iTunes') || trackForPlayer('spotify')
if (currentTrack) {
app = Application.currentApplication()
app.includeStandardAdditions = true;
return currentTrack
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment