0

I'm currently trying to read the name of a process in Go how it is represented in the windows task manager.

However, when I read it in Go it is displayed always as the executable. I'm trying to get it how it is named in the task manager.

Code:

package main

import (
    "fmt"

    "github.com/shirou/gopsutil/process"
)

func main() {
    p, _ := process.Processes()
    for _, pr := range p {
        fmt.Println(pr.Name())
    }
}

This outputs all process names but none match how it is shown here:

enter image description here

I am trying to read the Spotify process name that is displayed with the song title.

madzohan
  • 11,488
  • 9
  • 40
  • 67
Uzair Ashraf
  • 1,171
  • 8
  • 20

1 Answers1

0

Get window title

Each time you open the "Windows Task Manager" it searches for .Net process.MainWindowTitle property, so you cant grep Windows title using gopsutil ... you have to use some Go wrapper for the .NET Core Runtime , not sure maybe this one would be helpful ... or even use C# instead of Golang

Get currently playing track on Spotify

Spotify has awesome docs with API usage for such case so you only need to generate auth token and convert next curl request to golang fetch function

curl -X "GET" "https://api.spotify.com/v1/me/player/currently-playing?market=UA" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer <<YOUR TOKEN>>"
madzohan
  • 11,488
  • 9
  • 40
  • 67