Created
March 13, 2025 12:32
-
-
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)
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
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