The question is related to bash and Linux like Debian; Ubuntu or Linux Mint.
It's known to open a new firefox window by bash on follow way:
Firefox
It's known to open a new Firefox tab on follow way:
Firefox https://stackoverflow.com
How to open a new Firefox on a size of x% of display size by bash and without awk?
How I do this, using xdotool
and wmctrl
:
#!/bin/bash
targetUrl="${1:-https://stackoverflow.com/search?tab=votes&q=user%3A1765658+firefox}"
geometry=1200x900+200+120
mkBound() { local refstr=({0..9} _ {A..Z} = {a..z}) tfmt
printf -v tfmt %8s
tfmt=(${tfmt// /%s}{,,}{,}) tfmt=${tfmt[*]} tfmt=${tfmt// /-}
printf -v bound $tfmt ${refstr[RANDOM%64]}{,,}{,,,}{,,,}
}
mkBound
printf -v ffurl "data:text/html;ascii,<head><title>%s</title></head>" $bound
firefox --new-window "$ffurl"
while ffwin=$(wmctrl -l|sed -ne "/$bound/s/ .*$//gp");[[ -z ${ffwin} ]] ;do
echo -n .
sleep .05
done
echo
IFS='+x' read -r width height xpos ypos <<<"$geometry"
xdotool windowraise $ffwin
xdotool windowfocus $ffwin
xdotool windowactivate $ffwin
sleep .8
xdotool windowmove $ffwin $xpos $ypos
xdotool windowsize $ffwin $width $height
xdotool windowactivate $ffwin
sleep .2
xdotool key ctrl+l
xdotool type --delay 22 "$targetUrl"
xdotool key Return
Save this in a script, then run them with an url as argument.
You could replace --new-window
by --private-window
if needed.
Nota: I use a 48 random chars string as bound to force firefox to title this string in order to ensure wmctrl
will find only this window...
You could replace 4th line:
geometry=1200x900+200+120
by either:
psize=40
while IFS=' +x' read cmd a b c d ;do
[[ $cmd == -geometry ]] &&
geometry=$((a*psize/100))+$((b*psize/100))+$c+$d
done < <(xwininfo -root)
or even...
psize=40
ar=('')
while IFS=' x+' read dev stat a b c d e f; do
if [[ $stat == connected ]]; then
typ=sec
[[ $a == primary ]] &&
typ=${a::3} a=$b b=$c c=$d d=$e
printf '%3d: %s (%s)\n' ${#ar[@]} $dev $typ
ar+=($((a*psize/100))+$((b*psize/100))+$c+$d)
fi
done < <(xrandr)
read -p 'Wich display: ' -rsn 1 userKey
if [[ ${ar[userKey]} ]]; then
geometry=${ar[userKey]}
echo $userKey
else
echo user abort
exit 1
fi
You may find a full version on my site (not on github;) using getopts
for
Usage: soFirefox [-h] [ -g str | [ [ -p int | [-x int] [-y int] ] [-d str] [URL]
-d str Display either 'HDMI-1', 'DP-2', 'secondary', 'root' or 'primary'.
-g str Geometry string in format 'WxH+X+Y' (must be alone).
-h Show this.
-p int Percent of display.
-x int Percent width of display.
-y int Percent height of display.
URL Default to 'https://stackoverflow.com/search?tab=votes&q=user%3A1765658+firefox'.
You can run:
soFirefox -d primary -y 80 -x 60 https://stackoverflow.com/a/75327166/1765658