Google play music desktop player

touch-bar

#1

Here is some scripts to enable current song info on touchbar and for play/pause button

set milefile to ("Macintosh HD:Users:kazak:Library:Application Support:Google Play Music Desktop Preformatted textPlayer:json_store:playback.json") -- enter here name of your user
set theFileContents to (read file milefile)


if application "Google Play Music Desktop Player" is running then
   tell application "JSON Helper" --you need to install JSON Helper from App Store
   	--Get UK police forces information	
   	set forceDetails to read JSON from theFileContents
   	set title to artist of song of forceDetails & " - " & title of song of forceDetails
   	
   	if playing of forceDetails then return title
   end tell
end if
return ""
set theFileContents to (read file milefile)

if application "Google Play Music Desktop Player" is running then
   tell application "JSON Helper"
   	--Get UK police forces information	
   	set forceDetails to read JSON from theFileContents
   	
   	if playing of forceDetails then return "pause"
   end tell
end if

if application "iTunes" is running then
   tell application "iTunes"
   	if player state is playing then return "pause"
   end tell
end if
return "play"


#2

Thank you so much for this – so great. I'm trying to add to it by adding a shuffle button. Having some trouble. Let me know if you have any advice!


#3

I've added a bit more code in to display the current time + total time of the playing track (may have bugs but from my testing it seems to work fine):

-- SETUP:
-- 1. Install "JSON Helper" from the Mac App Store and grant permissions for BTT to access it when prompted.
-- 2. Create a new AppleScript "Return Value" widget in BTT and paste this code in
-- 3. Edit the line below to change to your user's directory and confirm the path to 'playback.json' is correct.

set milefile to ("Macintosh HD:Users:drawcard:Library:Application Support:Google Play Music Desktop Player:json_store:playback.json")
set theFileContents to (read file milefile)

if application "Google Play Music Desktop Player" is running then
	tell application "JSON Helper"
		set GPMDetails to read JSON from theFileContents
		set artist to artist of song of GPMDetails
		set title to title of song of GPMDetails
		-- current time counter (JSON string converted to MM:SS)
		set tcurrent to current of |time| of GPMDetails
		set curM to tcurrent div 60000
		set curS to text -2 thru -1 of ("0" & ((tcurrent div 1000) mod 60))
		-- total time counter (JSON string converted to MM:SS)
		set ttotal to total of |time| of GPMDetails
		set totM to ttotal div 60000
		set totS to text -2 thru -1 of ("0" & ((ttotal div 1000) mod 60))
		
		-- display all the values
		if playing of GPMDetails then return artist & " • " & title & " • " & curM & ":" & curS & " / " & totM & ":" & totS
	end tell
end if
return ""

It also helps to keep the counter continuously refreshed by setting "Execute every x seconds" to 0.25 and also checking "Always run when widget becomes visible"


#4

In recent BTT versions there is already an now playing widget, that supports GPMDP


#5

I see, thanks for letting me know :slight_smile:


#6

GPMDP have really complicated method of taking commands. I was trying to add some functions like like/dislike, but it receives only websocket commands and I did not found any option to send WS from BTT shell executor.


#7

Yeah from what I see the JSON only reports if a track was liked or disliked, and you can't actively set that. It's a shame but with all the talk about GPM shutting down / being replaced with Youtube Music, there probably won't be a heap of movement on it in the future.