Skip to content

Instantly share code, notes, and snippets.

@kcsongor
Created March 10, 2018 14:55
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 kcsongor/401cd6e1d29721a9076a5676a08751ce to your computer and use it in GitHub Desktop.
Save kcsongor/401cd6e1d29721a9076a5676a08751ce to your computer and use it in GitHub Desktop.
Vim: Get currently playing song from iTunes
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