Skip to content

Instantly share code, notes, and snippets.

@even4void
Created August 27, 2025 19:44
Show Gist options
  • Save even4void/b207c1e402fd7787e00e6685f843aee1 to your computer and use it in GitHub Desktop.
Save even4void/b207c1e402fd7787e00e6685f843aee1 to your computer and use it in GitHub Desktop.
Now playing for Cmus and Apple Music on macOS
#!/bin/sh
unset title
if info=$(cmus-remote -Q 2>/dev/null); then
status=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "status " | cut -d ' ' -f 2)
if [ "$status" = "playing" ] || [ "$status" = "paused" ] || [ "$status" = "stopped" ]; then
title=$(echo "$info" | grep -v 'set ' | grep " title " | cut -d ' ' -f 3-)
artist=$(echo "$info" | grep -v 'set ' | grep " artist " | cut -d ' ' -f 3-)
fi
else
title=$(osascript -e 'if application "Music" is running then' -e 'tell application "Music" to get name of current track' -e 'end if')
artist=$(osascript -e 'if application "Music" is running then' -e 'tell application "Music" to get artist of current track' -e 'end if')
fi
if ${title+"true"}; then
title=$(echo "$title" | cut -b 1-15)
artist=$(echo "$artist" | cut -b 1-15)
echo "$artist • $title"
fi
# -%<---
set -g status-interval 5
set -g status-justify left
set -g status-left ""
set -g status-right-length 60
set -g status-position top
set -g status-right "#[align=absolute-centre] %H:%M #[align=right]#{?client_prefix,#[noreverse] N #[reverse],} #(np) #{?#{==:#{pane_current_command},ssh},#[noreverse] #{pane_current_command} #[reverse],#{pane_current_command}} ♯#S "
if '! [ -z "$SSH_TTY" ]' 'set -g status-right "#{?client_prefix,#[noreverse] N #[reverse],} #{?#{==:#{pane_current_command},ssh},#[noreverse] #{pane_current_command} #[reverse],#{pane_current_command}} #(whoami)@#h ♯#S "'
set -g status-style reverse
set -g message-command-style reverse
set -g message-style reverse
set -g window-status-current-format "#[bg=black,fg=white,reverse] #I#{?window_zoomed_flag,+,} "
set -g window-status-format "#[fg=dim] #I#{?pane_synchronized,~,} "
set -g window-status-separator "#[fg=dim]"
set -g window-status-activity-style blink
# --->%-
@even4void
Copy link
Author

even4void commented Aug 27, 2025

I renamed the script np (no extension), and chmod +x. Of note, artiste and title are truncated to 15 characters each. The right status line of Tmux has been increased to 60 char; maybe you'll need more room depending on what you display in this part of the status line. Below is a screenshot of Neovim 0.11 and Cmus 2.12 running in Apple Terminal on macOS Sequoia 15.6.1. It also works with Apple Music.

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment