Documentation for GCR Image Deletion Script
This document provides an overview of a Bash script designed to automate the deletion of Google Container Registry (GCR) images on Google Cloud using mouse and keyboard automation. The script utilizes the xdotool tool and is bound to a keyboard shortcut for quick activation on Ubuntu.
Purpose
The script automates the following actions:
- Simulates mouse clicks at specific coordinates in a browser to interact with the GCR user interface.
- Switches the browser tab to perform additional operations.
Prerequisites
1. Install xdotool
Ensure that xdotool is installed on your Ubuntu system. To install:
sudo apt-get update
sudo apt-get install xdotool2. Script File
Save the script as a .sh file, e.g., delete_gcr_images.sh. The script is as follows:
#!/bin/bash
sleep 3 # Gives you time to position cursor
#xdotool click --repeat 1 1
xdotool mousemove 1648 566 click 1
xdotool mousemove 1847 230 click 1
sleep 0.5
xdotool mousemove 2530 731 click 1
xdotool mousemove 2535 760 click 1
sleep 0.5
xdotool key --clearmodifiers ctrl+Tab3. Keyboard Shortcut Setup
To bind the script to a keyboard shortcut:
- Open the Settings on Ubuntu.
- Navigate to Keyboard Shortcuts.
- Click Add Custom Shortcut.
- Enter the following details:
- Name: Delete GCR Images
- Command:
/path/to/delete_gcr_images.sh
- Assign a shortcut key combination, e.g.,
Ctrl + Shift + S.
Ensure the script has executable permissions:
chmod +x /path/to/delete_gcr_images.shHow It Works
- Activation: Press
Ctrl + Shift + Sto trigger the script. - Delay: A 3-second delay is added to allow you to position the cursor or switch to the appropriate browser window.
- Mouse Actions: The script moves the mouse to specific coordinates and performs clicks to delete GCR images.
- Coordinates can be adjusted based on your screen resolution or the browser UI layout.
- Tab Switch: The script simulates a
Ctrl + Tabkeypress to switch to the next browser tab.
Notes
- Adjust the coordinates in the script (
xdotool mousemove) to match your screen resolution and the location of the clickable elements in the GCR UI. - Add more actions to the script if additional steps are required for image deletion.
- Test the script with caution to avoid accidental clicks outside the intended targets.
Troubleshooting
- Script Not Working:
- Verify that
xdotoolis installed. - Check that the script has executable permissions.
- Ensure the correct path to the script is provided in the keyboard shortcut configuration.
- Verify that
- Coordinates Are Incorrect:
- Use the following command to identify precise screen coordinates:
xdotool getmouselocation
- Use the following command to identify precise screen coordinates:
- Keyboard Shortcut Not Responding:
- Confirm that the shortcut is properly configured in the system settings.
Disclaimer
The script is designed for automating browser actions in a controlled environment. Use responsibly and ensure compliance with Google Cloud policies and terms of service.