1

I'm trying to create an else/if statement in bash so that when a window renames itself to something. Example: The spotify renames to Sponsored Message or Advertisement) I can run an if to mute amixer, and else if it doesn't rename to either. My original plan was to base the automuter off notifications but since it isn't very accurate, I wanted to ask if anyone knew of reading the window and running a command.

Thanks :)

2
  • There is an answered question for detecting window title change using a Python script: unix.stackexchange.com/a/214939/53143
    – andrybak
    Feb 27, 2021 at 19:57
  • Added some scripting ideas and command recommendations will take a little testing but very doable. Feb 27, 2021 at 21:33

1 Answer 1

1

I think the best command to do this would be xdotool however I am not familiar with the Spotify app so you'll have to test if the xwindowname is updated by the app. Below is a list of commands to test this from there a simple script would be easy enough to write but first we need proof of concept.

pgreg <name of spotify app>
xdotool search --pid <pid returned by pgrep>
xdotool getwindowname <window id returned by xdotool search>

The last command will tell you the window name and then you can test if it is changed when the ads come on.

If everything works and the window name is changed when the ads play a simple script like.

NOTE: This is very rough to show the concepts not give a copy and paste answer.

#!/bin/bash

while true; 
do
pid=$(pgrep spotify)
win=$(xdotool search --pid $pid)
state=$(xdotool getwindowname $win | <filter for ads>)

if [[ $state = 'ads' ]]; then
     mute
else
     unmute
fi
done

Something like that very rough but get across the concept and idea.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .