Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save it-is-wednesday/37dc8462800269083d8ec6e6057251b4 to your computer and use it in GitHub Desktop.
Save it-is-wednesday/37dc8462800269083d8ec6e6057251b4 to your computer and use it in GitHub Desktop.
#!/bin/env python
"""
Hi! Running this script will copy to your clipboard the artist and title of the
currently played Spotify track. It will be copied in the format of `{artist} - {title}`.
Requires Termux:Widget and Termux:API, and you'll need to enable notification
access for Termux (you'll be prompted to).
This is intended to be run through a widget. Put this script under
~/.shortcuts/tasks so it will not open an annoying ass terminal when launched,
but rather will just run in background.
"""
import json
from subprocess import run
proc = run(["termux-notification-list"], capture_output=True, encoding="UTF-8")
notifications = json.loads(proc.stdout)
spotify = next(n for n in notifications if n["packageName"] == "com.spotify.music")
title = spotify["title"]
artist = spotify["content"]
run(["termux-clipboard-set", f"{artist} - {title}"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment