The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 4,419β€…    Votes:  6β€…    βœ… Solution
Tags: command-line   bash   gnome-shell   window-manager   xdotool  
Link: πŸ” See Original Question on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1147294
Title: xdotool how to select desktop send F5 and return?
ID: /2019/05/30/xdotool-how-to-select-desktop-send-F5-and-return_
Created: May 30, 2019    Edited:  May 31, 2019
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


It sounds simple; xdotool selects desktop, simulates F5 key press and returns focus to calling window / program.

After googling though it doesn’t sound simple anymore.

I need to do this from bash / gnome-shell.

Any ideas?


This project is related to this Q&A where the icons drop off the left screen into a black whole because of different sized monitors:

Thanks to Podesta’s help I created this code:

TestIcons () {

    [[ $TestSeconds == "" ]] || [[ $TestSeconds == 0 ]] && TestSeconds=5

    local i Position File
    for (( i=0; i<${#IconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
        File="$ICONS_DIR"/"${IconsArr[((i+ICON_NAME_NDX))]}"
        Position="${IconsArr[((i+ICON_COL_NDX))]},${IconsArr[((i+ICON_ROW_NDX))]}"
        gvfs-set-attribute -t string "$File" \
                'metadata::nautilus-icon-position' "$Position"
    done

    wmctrl -k on        # Show desktop
    xdotool key F5      # Refresh desktop (show icon new positions)
    sleep $TestSeconds  # Pause for view
    wmctrl -k off       # Restore windows

    for (( i=0; i<${#OldIconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
        File="$ICONS_DIR"/"${OldIconsArr[((i+ICON_NAME_NDX))]}"
        Position="${OldIconsArr[((i+ICON_COL_NDX))]},${OldIconsArr[((i+ICON_ROW_NDX))]}"
        gvfs-set-attribute -t string "$File" \
                'metadata::nautilus-icon-position' "$Position"

    done

    wmctrl -k on        # Show desktop
    xdotool key F5      # Refresh desktop (show icon new positions)
    wmctrl -k off       # Restore windows

} # TestIcons

This is what the screen looks like:

iconic 2 optimized.gif

⇧ What does shellcheck warning SC2129 β€œConsider using { cmd1; cmd2; } >> file instead of individual redirects.” mean? How can I include the cursor in the screenshots created when PrtScr is pressed?  β‡©