Scripting open existing window instead of new window
I'm trying to script a dunst/Spotify interaction to dunstify playerctl metadata and open Spotify tracks by way of spotify --uri=$(playerctl -p spotify metadata mpris:trackid) when it's dismissed/clicked.
How can I make sure the existing Spotify window is opened rather than a brand new window?
If the answer requires very program-specific API knowledge, then it would be helpful if someone could provide a practical approach to handling this problem.
I'm also curious about this in order to enhance how rofi handles app-switching, to intervene with whether it should open a new window or an existing window (outside the context of rofi -modi window which handles intentional window switching).
---
Edit: I guess the appropriate way to handle something like this would be to check if the process is running and focus the window, otherwise open the application.
Posted Jan 10, 2020, 6:37 PM UTC · edited
Try using dbus like so:
Thank you for the suggestion. Unfortunately, rather than just pulling up the track, it restarts the track. However that's probably the expected behavior for the URI. I think for now I'll just use
i3-msg '[class="Spotify"] focus'.Some related posts I found: