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:
sudo apt update
sudo apt install xdotool wmctrlCreate a script (e.g., ~/window_script.sh) that runs your desired actions when a new window opens. For example:
#!/bin/bash
# Your script logic here
echo "New window opened: $(wmctrl -l -p | tail -n 1)" >> ~/window_log.txtMake the script executable:
chmod +x ~/window_script.shUse a loop with wmctrl to monitor for new windows:
#!/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:chmod +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?
Vibe can make mistakes. Check answers. Learn more