The script I made below works for me, only requires wmctrl
. You can get this on Ubuntu with the command sudo apt-get install wmctrl
.
If needed, you may need to make some minor modifications.
$BEFORE_WINDOW_NAME
must be set to the last string of your computer name pulled (you can view this from System Settings
>Details
>Device name
).
$MONITORS
this will work with 2 monitors (with a resoloution of 1920x####
) although you may re-define this variable by setting an element for each monitor connected to your device and setting it to any x
coordinate on that screen.
$SKIPPED_WINDOWS
is a list of windows you do not want to move when this script is called. Feel free to add or remove items. List of items can be view by typing in the command
wmctrl -l
.
Finally, this script take in one parameter ie : window_control.sh n
, where n
is the monitor the to move the windows.
#! /bin/bash
IFS=$'\n' #prevents window names from breaking in loop
#Computers Name
#change this to the last characters before window names
#0x02a00002 0 mycomputer-Envy-M3970 XdndCollectionWindowImp -> ie:last characters in computer name
BEFORE_WINDOW_NAME="M3970" #MODIFY ME!!
WINDOWS=$(wmctrl -l | grep -oh -P "(?<=$BEFORE_WINDOW_NAME\ ).*")
#MODIFY MONITORS if needed
declare -a MONITORS=(
'0' # Monitor 1
'2150' # Monitor 2
);
declare -a SKIPPED_WINDOWS=(
'XdndCollectionWindowImp'
'unity-launcher'
'unity-panel'
'unity-dash'
'Hud'
'Desktop'
'Ubuntu'
);
#loop through window names and move them
for i in $WINDOWS; do
if [[ " ${SKIPPED_WINDOWS[@]} " =~ " ${i} " ]]; then
# whatever you DO NOT want to do when arr contains value
# echo "Skipping $i"
echo ""
else
# whatever you want to do when arr contains value
echo "Moving $i"
wmctrl -r "$i" -b remove,maximized_vert,maximized_horz
wmctrl -r "$i" -e 0,"${MONITORS[$1]}",0,800,800
wmctrl -r "$i" -b add,maximized_vert,maximized_horz
fi
done