#!/bin/sh DEFAULT_PROFILE="auto" SAVEPATH="/tmp/wpos" mkdir -p "$SAVEPATH" if [ "$1" = "save" ]; then wmctrl -lxG > "$SAVEPATH/$DEFAULT_PROFILE" exit 0 elif [ "$1" = "restore" ]; then cat "$SAVEPATH/$DEFAULT_PROFILE" | while read LINE; do ## Parse records in savefile ID="$(echo "$LINE" | awk '{ print $1 }')" GRAVITY="$(echo "$LINE" | awk '{ print $2 }')" POSX="$(echo "$LINE" | awk '{ print $3 }')" POSY="$(echo "$LINE" | awk '{ print $4 }')" WIDTH="$(echo "$LINE" | awk '{ print $5 }')" HEIGHT="$(echo "$LINE" | awk '{ print $6 }')" ## Check few important values [ "$GRAVITY" -lt 0 ] && continue [ "$(($POSY - 40 ))" -ge 0 ] && POSY=$(($POSY - 40)) ## And run command wmctrl -i -r "$ID" -e "$GRAVITY","$POSX","$POSY","$WIDTH","$HEIGHT" done fi