Skip to content

Instantly share code, notes, and snippets.

@CliffS
Last active October 19, 2023 01:27
Show Gist options
  • Save CliffS/bd7a65427e03217161d8dcad9ec3878d to your computer and use it in GitHub Desktop.
Save CliffS/bd7a65427e03217161d8dcad9ec3878d to your computer and use it in GitHub Desktop.
#!/bin/bash
MAX=20 # maximum numbe of loops
LOGFILE=~/tmp/start-and-move.log
rm -f $LOGFILE
log() {
echo "$@" | ts '%Y-%m-%d %H:%M:%S' >> $LOGFILE
}
move_resize() {
local winclass=$1
local workspace=$2 # zero to max-workspaces (-1 means all workspaces)
local x=$3
local y=$4
local width=$5
local height=$6
local result=""
local count=0
while [[ ! $result =~ '(true' ]] && (( $((count=count+1)) < $MAX ))
do
sleep 1
log "$winclass: $x $y $width $height (count = $count)"
result=$(gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "
// let space = global.workspace_manager.get_workspace_by_index($workspace)
let win = global
.get_window_actors()
.map(a=>a.meta_window)
.map(w=>({
class: w.get_wm_class(),
title: w.get_title(),
ws: w
})
)
.find(ws => ws.class == '$winclass')
if (win) {
win.ws.change_workspace_by_index($workspace, false)
win.ws.move_resize_frame(0, $x, $y, $width, $height)
}
else {
throw 'Not found'
}
"
)
done
}
sleep 2
firefox &
thunderbird &
Telegram &
franz &
speedcrunch &
gnome-terminal
sleep 5
move_resize 'firefox' 0 2593 958 1283 1166 &
move_resize 'TelegramDesktop' -1 1758 1804 800 637 &
move_resize 'Franz' 1 10 1832 1007 778 &
move_resize 'SpeedCrunch' -1 5760 1607 640 517 &
move_resize 'gnome-terminal-server' 0 3876 1643 1364 481 &
sleep 8 && move_resize 'thunderbird' 1 2588 1113 1237 1004 & # tb takes forever to initialise
ydotool key meta+1 # a cheeky way of getting back to the first workspace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment