xdotool how to select desktop send F5 and return?

Script below work of @WinEunuuchs2Unix and is the final solution. My original answer is at the end.

#!/bin/bash

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

A few other xdotools commands that can be useful in similar situation:

If your window manager has a show desktop command, it can be useful to minimize, and bring back all windows. Usually it is set to ctrl+alt+d:

xdotool key ctrl+alt+d

If you want to save the currently active window, to later bring it back, you can use:

myWindow="$(xdotool getactivewindow)"

Ti minimize a window you can use. Adding it to a loop allows you to minimize all windows, as an alternative to the show dekstop.

xdotool windowminimize $(xdotool getactivewindow)

To bring the active window you saved back to the focus:

xdotool windowactivate "$myWindow"

To close the active window use:

xdotool getactivewindow windowkill

And most important, all those commands that you can use with active window, you can actually search and apply to specific cases. For example, searching for this specific window, based on the title.

xdotool search --desktop 0 --name "command line - xdotool" windowactivate

There are many different ways of searching for windows, based on the title, the class, if they are visible, etc. It can also manipulate both windows positions and the mouse. The manpage for xdotol is very comprehensive. Combining them with a bash script would give plenty of freedom to achieve most things.