Skip to content

Instantly share code, notes, and snippets.

@ChronSyn
Created March 13, 2025 12:32
Show Gist options
  • Save ChronSyn/2d3eb95353f24b914a6b71113bf41f05 to your computer and use it in GitHub Desktop.
Save ChronSyn/2d3eb95353f24b914a6b71113bf41f05 to your computer and use it in GitHub Desktop.
Powershell / Windows - Get currently playing Spotify song title and artist to JSON output (using Spotify application window title)
while ($true) {
$processes = Get-Process spotify
$title = (Out-String -InputObject $processes.mainWindowTitle) -replace "`n","" -replace "`r",""
$song = $null
$artist = $null
$songTitle = $null
$jsonOutput = $null
$jsonOutputAsJson = $null
if (-Not $title.Contains('Spotify')) {
$song = $title
$artist = $title.split(" - ")[0]
$songTitle = $title.split(" - ")[1]
$jsonOutput = @{
'artist' = $artist
'song_title' = $songTitle
}
$jsonOutputAsJson = $jsonOutput | ConvertTo-Json
}
$jsonOutputAsJson > ./currentSong.json
cls
Write-Output "$jsonOutputAsJson"
Start-Sleep -Seconds 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment