Created
March 10, 2018 14:55
-
-
Save kcsongor/401cd6e1d29721a9076a5676a08751ce to your computer and use it in GitHub Desktop.
Vim: Get currently playing song from iTunes
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
function! s:current_track() | |
let queries = ['album of the current track', | |
\ 'artist of the current track', | |
\ 'name of the current track', | |
\ 'the player position'] | |
let query = "osascript -s s -e 'tell application \"iTunes\" to return " | |
\ . join(queries, ' & "----" & ') . "'" | |
let song_info = split(split(system(query), "\n")[0][1:-1], "----") | |
return { 'album' : song_info[0], | |
\ 'artist' : song_info[1], | |
\ 'title' : song_info[2], | |
\ 'seconds': split(song_info[3], '\.')[0] | |
\ } | |
endfunction | |
function! CurrentTrack() | |
let track = s:current_track() | |
return track.artist . " - " . track.title . " (" . track.album . ")" | |
endfunction! | |
nnoremap <silent> <leader>ip :echo CurrentTrack()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment