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:
1. Use xdotool and wmctrl
These tools allow you to detect and interact with windows.
-
Install the tools:
sudo 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:
#!/bin/bash
# Your script logic here
echo "New window opened: $(wmctrl -l -p | tail -n 1)" >> ~/window_log.txt
-
Make the script executable:
chmod +x ~/window_script.sh
2. Detect New Windows
Use 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
3. Run the Monitor Script at Startup
4. Alternative: Use GNOME Extensions
If you prefer a GUI-based approach:
- Install the GNOME Shell Extension "Window List" or similar.
- Use extensions like "Run on Window Open" (if available) to trigger scripts.
5. Debugging
- Check logs (
~/window_log.txt) to ensure the script runs as expected.
- Adjust the sleep interval in the monitor script for performance.
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?