To run a script each time a new GNOME window opens on Debian, you can use a combination of GNOME's built-in tools and scripting. Here’s a step-by-step approach:
xdotool and wmctrlThese tools allow you to detect and interact with windows.
Install the tools:
bashsudo apt update sudo apt install xdotool wmctrl
Create a script (e.g., ~/window_script.sh) that runs your desired actions when a new window opens. For example:
bash#!/bin/bash # Your script logic here echo "New window opened: $(wmctrl -l -p | tail -n 1)" >> ~/window_log.txt
Make the script executable:
bashchmod +x ~/window_script.sh
Use a loop with wmctrl to monitor for new windows:
bash#!/bin/bash while true; do wmctrl -l sleep 1 done | while read -r line; do # Check if the window is new (you may need to track previous windows) ~/window_script.sh done
~/window_monitor.sh) and make it executable:
bashchmod +x ~/window_monitor.sh
~/window_monitor.sh.If you prefer a GUI-based approach:
~/window_log.txt) to ensure the script runs as expected.Note: This approach is not foolproof—it polls for new windows rather than using event-driven triggers. For a more robust solution, consider using a window manager hook or a dedicated tool like devilspie2.
Would you like help refining the script for a specific use case?