Show Floating Webview

I would like to make a shortcut that chooses a random album from my Spotify library. I was hoping I could use the site Spotify Random Album Selector

I've tried setting up a floating webview action and it displays the page okay, but the Login with Spotify button doesn't work.

Any ideas?

What happens if you press the login button?

I was able to log in in the floating web view, but it wants to open a new windows when clicking on one of the albums. Do you want it to open the spotify app?

Nothing was happening at all, but that was on my Mojave computer. I've since tried it on Monterey and login works!

Yes ideally it would open the Spotify app, but I see now that it tries to open the web player. I guess I hadn't thought it through entirely.

you can use this config to open the albums in the spotify app:

Open URLs with prefix in system browser:
spotify://

User Script:

setInterval(() => {var anchors = document.getElementsByTagName("a");

for (var i = 0; i < anchors.length; i++) {
    anchors[i].href = anchors[i].href.replace('https://open.spotify.com', 'spotify:/');
}
},1000);


Thanks! This is getting close. Would be great if Spotify immediately started playing the album when clicked. I'm not sure if it's possible. I read that appending :play to the spotify:// link should do this, but that doesn't work for me. :play might be no longer supported.

Since the spotify:// links don't play straight away, I'm going to try a different approach. I've found that the following Applescript will make the Spotify desktop client start playing an album immediately:

tell application "Spotify"
	play track "spotify:album:4CBUbnGFz2iKFJjYqRIwst"
end tell

So I'm thinking I could replace the anchors with a btt:// links to a named action. But I haven't been able to workout a way to pass the album's UID to the action. @Andreas_Hegenberg Is there a way to pass a value to a btt named action via the query string when calling it via the the custom URL scheme?

I think the easiest would be to replace all links with java script function calls like this:
//edit, here a working JavaScript:

 setInterval(() => {var anchors = document.getElementsByTagName("a");

for (var i = 0; i < anchors.length; i++) {
     

    anchors[i].onclick = (e) => {
    const originalLink = e.target.parentElement.href; 
    const lastPartOfURL =  originalLink.substring(originalLink.lastIndexOf('/') + 1);
    const appleScriptToRun = `tell application "Spotify"
                                play track "spotify:album:${lastPartOfURL}"
                               end tell`

console.log('opening album with script', appleScriptToRun);

           runAppleScript({script: appleScriptToRun});
     }
} 

},1000);

Works pretty well, I might be using this for myself :slight_smile:

When using this you might need to remove the "spotify://" prefix you added previously.