Advertisement
smeech

espanso_move.sh

Aug 18th, 2024 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #!/bin/bash
  2. # Espanso doesn't facilitate repositioning of its Search or Choice etc. windows.
  3. # If the following script is running in the background, it will await the opening
  4. # of the window, and move it to the top left of the screen.
  5. # Adjust the middle two coordinates (,0,0,) for a different position, and reduce
  6. # the lower sleep value (included to reduce CPU load) if it's too slow
  7.  
  8. # Exact window title to match
  9. WINDOW_TITLE="espanso"
  10.  
  11. # Function to get the window ID based on the window title
  12. get_window_id() {
  13.   local title="$1"
  14.   wmctrl -l | awk -v title="$title" '$NF == title {print $1}'
  15. }
  16.  
  17. while true; do
  18.   # Get the window ID using the function
  19.   WINDOW_ID=$(get_window_id "$WINDOW_TITLE")
  20.  
  21.   # If the window is found
  22.   if [ ! -z "$WINDOW_ID" ]; then
  23.     wmctrl -i -r "$WINDOW_ID" -e 0,0,0,-1,-1
  24.     echo "Window '$WINDOW_TITLE' moved to the top-left corner."
  25.    
  26.     # Loop until the window is no longer found
  27.     while [ ! -z "$(get_window_id "$WINDOW_TITLE")" ]; do
  28.       sleep 1  # Keep checking every second if the window is still open
  29.     done
  30.    
  31.     echo "Window '$WINDOW_TITLE' closed or minimized. Waiting for it to reappear."
  32.   fi
  33.  
  34.   sleep 0.5  # Check for the window's existence every 0.5 seconds
  35. done
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement