Skip to content

Instantly share code, notes, and snippets.

@zumikkebe
Last active December 31, 2023 23:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zumikkebe/1aea6d017eb78ba672a751cf78ef9810 to your computer and use it in GitHub Desktop.
Save zumikkebe/1aea6d017eb78ba672a751cf78ef9810 to your computer and use it in GitHub Desktop.
winpwnr.sh is a one-liner Haikus' hey front-end with the intent to domate windows
#! /bin/bash
Usage()
{
echo "usage: ${script_name} [-D] [-a value] [-dhl] [-s value] [-f] [-twLFGpPMAmHnr value]
-D automatically detects the current active window, obtaining the name of the application and the ID number
-a select the application by name
-d avoid DeskBar
-h print this help
-l list windows of the selected application
-s select application window via ID number or title
-f force fullscreen for the selected window
-t change the title of the selected window
-w show the selected window on {x} workspace(s),
- set multiple values separated by any character, like \"1,2,4,5\" or \"5.6.1\"
- use \"a|all\" to show the selected window in every workspace
- use l|left, r|right, u|up and d|down to show the selected window in the adjacent workspace by the given direction
-L change the LOOK of the selected window:
- b OR bordered
- n OR no-border
- t OR titled
- d OR document
- m OR modal
- f OR floating
-F change the FEEL of the selected window:
- n OR normal
- ms OR modal-subset
- mp OR modal-app
- ml OR modal-all
- fs OR floating-subset
- fp OR floating-app
- fl OR floating-all
-G change the FLAGS of the selected window, multiple values are accepted separated by commas
- nm OR not-movable
- nr OR not-resizable
- nh OR not-h-resizable
- nv OR not-v-resizable
- fs OR accept-first-click
- nc OR not-closable
- nz OR not-zoomable
- af OR avoid-front
- nw OR no-workspace-activation
- as OR avoid-focus
- nb OR not-minimizable
- na OR not_anchored
- sp OR same-position
- ce OR close-on-escape
- l OR lock (shortcut for nm,nc,nr,nb,nz)
- r OR reset
-p move the selected window by [x,y] pixels (relative)
-P move the selected window to [x,y] (absolute) position
-r resize the frame of the selected window to [width, height], centering it with the original one and avoiding to exit the edges of the screen
omit a value to preserve the current one (i.e. -r ,300; -r 300, ), use any letter to enlarge to max size (i.e. -r f,200; -r 200,f )
-M minimize the selected window [1|t|true|on|y|yes,0|f|false|off|n|no,toggle]
-A active the selected window [1|t|true|on|y|yes,0|f|false|off|n|no,toggle]
-m move the selected window against the edges and corners of the screen:
7 8 9 ul u ur up-left up up-right
4 5 6 OR l c r OR left center right
1 2 3 dl d dr down-left down down-right
combine the option center + selected edge to move the selected window centered against the edge to a centered position (i.e. use -m 45, 54, cl, lc, center-left or left-center)
ce or closest-edge moves the window against the closest edge
cc or closest-corner moves the window against the closest corner
-H as the -m option but the selected window will be moved against the edges, resized to halves of the screen size, resized to quarters of the screen size to the corners
-n as the -m option but the selected window will be moved against the edges, resized to ninths of the screen size
with this option it is possible to assign a group of adjacent ninths to the selected window using the digits (numpad)
░ ░ ░
░ ░ ░
I.E.: -n 12 █ █ ░
░ █ █
░ █ █
-n 59 ░ ░ ░
░ █ ░
░ █ ░
-n 28 ░ █ ░
Insert the digits that match the screen portions you want to take care of the window, the script is not restrictive about the order of the digits, it reorders and discards what is not necessary, so it is possible to enter 12 or 21, 28,82,258,285,582,etc. or 59,95,9586,etc., just make sure only to select the ends of the desired area"
[ ${1} ] && exit 1 || exit
}
###
Discovery()
{
while read app_name
do
while read win_count
do
for ((win_ID=0;win_ID<${win_count};win_ID++))
do
[ "`timeout 0.1 hey -o "${app_name}" get Active of Window ${win_ID}`" == "true" ] && return
done
done <<< `hey -o ${app_name} count of Window`
done <<< `roster | grep -v 'server' | awk '/\(/{print $2}' FS='[()]' | sort -u`
echo "Something weird happened, no active window has been found!"
exit 1
}
###
CheckArgs()
{
if [ $(echo -n "$1" | wc -c) -eq 2 ] && [ $(echo -n "$1" | awk '/-/{print}') ]
then
shift $((OPTIND-1))
return 1
fi
}
###
SetWorkspace ()
{
case ${1} in
a|all)
hey -o "${app_name}" set Workspaces of Window "${win_ID}" to -1
;;
l|left|r|right|u|up|d|down)
hey -o "${app_name}" set Workspaces of Window "${win_ID}" to `(hey -o "${app_name}" get Workspaces of Window "${win_ID}" | awk '{printf "%s,",1+log($0)/log(2)}'; \
message ${XDG_CONFIG_HOME}/system/app_server/workspaces | awk -F'[^0-9]' '/columns/,/rows/ {printf "%s,",$(NF-1)}') \
| awk \
-v dir=${1:0:1} -F',' '{
curr_ws=$1;columns=$2;rows=$3;
curr_column=(curr_ws-1)%columns+1;curr_row=int((curr_ws-curr_column)/rows)+1;
if(dir == "l") if(curr_column>1) print (curr_ws-1);
else print (columns*curr_row );
if(dir == "r") if(curr_column<columns) print (curr_ws+1);
else print (1+columns*(curr_row-1));
if(dir == "u") if(curr_row>1) print (curr_ws-columns);
else print (curr_column+((rows-curr_row)*columns));
if(dir == "d") if(curr_row<rows) print(curr_ws+columns);
else print (curr_column);
}' | awk '{printf "%s",2^($0-1)}'`
;;
*)
hey -o "${app_name}" set Workspaces of Window "${win_ID}" to `echo -n $1 | awk '{for(i=1;i<=NF;i++) print ($i-1)}' FS="[^0-9]" | sort -u | awk '{val+=2^($0)} END {print val}'`
;;
esac
}
###
EnlistWindows()
{
for (( i=0;i<=`echo $(hey "${app_name}" Count of Window | awk '/result/{print $4}') - 1 | bc`;i++ )); do echo -n "$i) ";hey "${app_name}" get Title of Window "$i" | awk '/result/{print $4}' FS="\""; done
}
###
ChangeTitle ()
{
hey -o "${app_name}" set Title of Window "${win_ID}" TO "$1"
}
###
ResizeFrame()
{
PeekDesktop
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[\
$((echo -n "$1,"; hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}'; echo -n ${dt_frame}) | awk '{\
if (!$1) {x_pos=$3; wx_pos=$5}\
else if ($1<$9) {x_pos=int($3+(($5-$3-$1)/2)); wx_pos=x_pos+$1; if (x_pos<0) {wx_pos-=x_pos;x_pos=0};if (wx_pos>$9){delta=(wx_pos-$9);wx_pos-=delta;x_pos-=delta}}\
else {x_pos=0;wx_pos=$9};\
if (!$2) {y_pos=$4; wy_pos=$6}\
else if ($2<$10) {y_pos=int($4+(($6-$4-$2)/2)); wy_pos=y_pos+$2; if (y_pos<0) {wy_pos-=y_pos;y_pos=0;};if (wy_pos>$10){delta=(wy_pos-$10);wy_pos-=delta;y_pos-=delta;}}\
else {y_pos=0;wy_pos=$10;};\
print x_pos,y_pos,wx_pos,wy_pos}' FS="," OFS=",")]
}
###
PlaceOnEdges()
{
PeekDesktop
case $1 in
7|ul|lu|left-up|up-left)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $5,$6,$5+($3-$1),$6+($4-$2)}' FS="," OFS=",")]
;;
1|dl|ld|left-down|down-left)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $5,($8-($4-$2)),$5+($3-$1),$8}' FS="," OFS=",")]
;;
3|dr|rd|right-down|down-right) # lower right corner. half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print ($7-($3-$1)),($8-($4-$2)),$7,$8}' FS="," OFS=",")]
;;
9|ur|ru|right-up|up-right)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print ($7-($3-$1)),$6,$7,$6+($4-$2)}' FS="," OFS=",")]
;;
5|c|center)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print int(($7-($3-$1))/2),int(($8-($4-$2))/2),int(($7+($3-$1))/2),int(($8+($4-$2))/2)}' FS="," OFS=",")]
;;
4|l|left)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $5,$2,$5+($3-$1),$4}' FS="," OFS=",")]
;;
6|r|right)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print ($7-($3-$1)),$2,$7,$4}' FS="," OFS=",")]
;;
2|d|down)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $1,($8-($4-$2)),$3,$8}' FS="," OFS=",")]
;;
8|u|up)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $1,$6,$3,$6+($4-$2)}' FS="," OFS=",")]
;;
58|85|uc|cu|center-up|up-center)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print int(($7-($3-$1))/2),$6,int(($7+($3-$1))/2),$6+($4-$2)}' FS="," OFS=",")]
;;
45|54|lc|cl|left-center|center-left)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print $5,int(($8-($4-$2))/2),$5+($3-$1),int(($8+($4-$2))/2)}' FS="," OFS=",")]
;;
65|56|rc|cr|right-center|center-right)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print ($7-($3-$1)),int(($8-($4-$2))/2),$7,int(($8+($4-$2))/2)}' FS="," OFS=",")]
;;
25|52|dc|cd|down-center|center-down)
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$((hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{print ($7-($3-$1))/2,($8-($4-$2)),int(($7+($3-$1))/2),$8}' FS="," OFS=",")]
;;
ce|closest-edge)
PlaceOnEdges `(hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{if((($2-$6)<($8-$4)) && (($1-$5)<($7-$3))) {if(($2-$6)<($1-$5)) print "u"; else print "l"};\
if((($2-$6)<($8-$4)) && (($1-$5)>($7-$3))) {if(($2-$6)<($7-$3)) print "u"; else print "r"};\
if((($2-$6)>($8-$4)) && (($1-$5)>($7-$3))) {if(($8-$4)<($7-$3)) print "d"; else print "r"};\
if((($2-$6)>($8-$4)) && (($1-$5)<($7-$3))) {if(($8-$4)<($1-$5)) print "d"; else print "l"};\
}' FS="," OFS=","`
;;
cc|closest-corner)
PlaceOnEdges `(hey "${app_name}" get Frame of Window "${win_ID}" | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${dt_frame}) | awk '{if(($2-$6)<($8-$4)) printf "u";else printf "d"; if(($1-$5)<($7-$3)) print "l";else print "r"; }' FS="," OFS=","`
;;
*)
Usage 1
;;
esac
}
###
SplitOnEdges()
{
PeekDesktop
case $1 in
7|ul|up-left) # upper left corner, half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3/2),int($4/2)}' FS="," OFS=",")]
;;
8|u|up) # upper half screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,$3,int($4/2)}' FS="," OFS=",")]
;;
9|ur|up-right) # upper right corner, half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/2),$2,$3,int($4/2)}' FS="," OFS=",")]
;;
4|l|left) # left half screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3/2),$4}' FS="," OFS=",")]
;;
5|c|center) # middle screen, half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/4),int($4/4),int($3*3/4),int($4*3/4)}' FS="," OFS=",")]
;;
6|r|right) # right half screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/2),$2,$3,$4}' FS="," OFS=",")]
;;
1|dl|down-left) # lower left corner. half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/2),int($3/2),$4}' FS="," OFS=",")]
;;
2|d|down) # lower half screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/2),$3,$4}' FS="," OFS=",")]
;;
3|dr|down-right) # lower right corner. half screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/2),int($4/2),$3,$4}' FS="," OFS=",")]
;;
*)
Usage 1
;;
esac
}
###
SplitOnThirds()
{
PeekDesktop
test $1 -eq $1 2>/dev/null
if ( [ $? -eq 0 ] && [ $1 -gt 9 ] )
then
min=9
max=0
for ((count=1;count<=$(echo -n $1 | wc -c);count++))
do
temp=$(echo -n $1 | cut -b${count})
[ ${temp} -lt ${min} ] && min=${temp}
[ ${temp} -gt ${max} ] && max=${temp}
done
case ${min}${max} in
12) # bottom left corner, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4*2/3),int($3*2/3),$4}' FS="," OFS=",")]
;;
13) # bottom row, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4*2/3),$3,$4}' FS="," OFS=",")]
;;
14) # bottom left corner, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),int($3/3),$4}' FS="," OFS=",")]
;;
15|24) # bottom left corner, 2/3 screen height, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),int($3*2/3),$4}' FS="," OFS=",")]
;;
16|34) # bottom row, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),$3,$4}' FS="," OFS=",")]
;;
17) # left column, 1/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3/3),$4}' FS="," OFS=",")]
;;
18|27) # left column, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3*2/3),$4}' FS="," OFS=",")]
;;
19|37) # fullscreen
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,$3,$4}' FS="," OFS=",")]
;;
23) # bottom right corner, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4*2/3),$3,$4}' FS="," OFS=",")]
;;
25) # bottom middle, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4/3),int($3*2/3),$4}' FS="," OFS=",")]
;;
26|35) # bottom right corner, 2/3 screen height, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4/3),$3,$4}' FS="," OFS=",")]
;;
28) # middle column, 1/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,int($3*2/3),$4}' FS="," OFS=",")]
;;
29|38) # right column, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,$3,$4}' FS="," OFS=",")]
;;
36) # bottom right corner, 2/3 screen height, 1/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),int($4/3),$3,$4}' FS="," OFS=",")]
;;
39) # right column, 1/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),$2,$3,$4}' FS="," OFS=",")]
;;
45) # middle left, 2/3 screen width, , 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),int($3*2/3),int($4*2/3)}' FS="," OFS=",")]
;;
46) # middle row, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),$3,int($4*2/3)}' FS="," OFS=",")]
;;
47) # upper left corner, 1/3 screen width, , 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3/3),int($4*2/3)}' FS="," OFS=",")]
;;
48|57) # upper left corner, 2/3 screen height, 2/3 screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3*2/3),int($4*2/3)}' FS="," OFS=",")]
;;
49|67) # upper row, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,$3,int($4*2/3)}' FS="," OFS=",")]
;;
56) # middle right, 2/3 screen width, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4/3),$3,int($4*2/3)}' FS="," OFS=",")]
;;
58) # upper middle, 1/3 screen width, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,int($3*2/3),int($4*2/3)}' FS="," OFS=",")]
;;
59|68) # upper right corner, 2/3 screen width, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,$3,int($4*2/3)}' FS="," OFS=",")]
;;
69) # upper right corner, 1/3 screen width, 2/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),$2,$3,int($4*2/3)}' FS="," OFS=",")]
;;
78) # upper left corner, 2/3 screen width, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3*2/3),int($4/3)}' FS="," OFS=",")]
;;
79) # upper row, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,$3,int($4/3)}' FS="," OFS=",")]
;;
89) # upper right corner, 2/3 screen width, 1/3 screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,$3,int($4/3)}' FS="," OFS=",")]
;;
esac
else
case $1 in
7|ul|up-left) # upper left corner, a third screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,$2,int($3/3),int($4/3)}' FS="," OFS=",")]
;;
8|u|up) # upper half screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),$2,int($3*2/3),int($4/3)}' FS="," OFS=",")]
;;
9|ur|up-right) # upper right corner, a third screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),$2,$3,int($4/3)}' FS="," OFS=",")]
;;
4|l|left) # left half screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4/3),int($3/3),int($4*2/3)}' FS="," OFS=",")]
;;
5|c|center) # middle screen, a third screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4/3),int($3*2/3),int($4*2/3)}' FS="," OFS=",")]
;;
6|r|right) # right half screen width
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),int($4/3),$3,int($4*2/3)}' FS="," OFS=",")]
;;
1|dl|down-left) # lower left corner, a third screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print $1,int($4*2/3),int($3/3),$4}' FS="," OFS=",")]
;;
2|d|down) # lower half screen height
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3/3),int($4*2/3),int($3*2/3),$4}' FS="," OFS=",")]
;;
3|dr|down-right) # lower right corner, a third screen size
hey -o "${app_name}" set Frame of Window "${win_ID}" TO BRect[$(echo ${dt_frame} | awk '{print int($3*2/3),int($4*2/3),$3,$4}' FS="," OFS=",")]
;;
*)
Usage 1
;;
esac
fi
}
###
FullScreen()
{
PeekDesktop
hey -o "${app_name}" set Frame of Window "${win_ID}" to BRect[${dt_frame}]
}
###
ChangeLook()
{
case $1 in
b|bordered)
hey -o "${app_name}" set Look of Window "${win_ID}" to 20
;;
n|no-border)
hey -o "${app_name}" set Look of Window "${win_ID}" to 19
;;
t|titled)
hey -o "${app_name}" set Look of Window "${win_ID}" to 1
;;
d|document)
hey -o "${app_name}" set Look of Window "${win_ID}" to 11
;;
m|modal)
hey -o "${app_name}" set Look of Window "${win_ID}" to 3
;;
f|floating)
hey -o "${app_name}" set Look of Window "${win_ID}" to 7
;;
*)
Usage 1
;;
esac
}
###
ChangeFeel()
{
case $1 in
n|normal)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 0
;;
ms|modal-subset)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 2
;;
mp|modal-app)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 1
;;
ml|modal-all)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 3
;;
fs|floating-subset)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 5
;;
fp|floating-app)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 4
;;
fl|floating-all)
hey -o "${app_name}" set Feel of Window "${win_ID}" to 6
;;
*)
Usage 1
;;
esac
}
###
SumFlags()
{
case $1 in
nm|not-movable)
let flags+=1
;;
nr|not-resizable)
let flags+=2
;;
nh|not-h-resizable)
let flags+=4
;;
nv|not-v-resizable)
let flags+=8
;;
fs|accept-first-click)
let flags+=16
;;
nc|not-closable)
let flags+=32
;;
nz|not-zoomable)
let flags+=64
;;
af|avoid-front)
let flags+=128
;;
nw|no-workspace-activation)
let flags+=256
;;
as|avoid-focus)
let flags+=8192
;;
nb|not-minimizable)
let flags+=16384
;;
na|not_anchored)
let flags+=131072
;;
sp|same-position)
let flags+=2097152
;;
ce|close-on-escape)
let flags+=8388608
;;
r|reset)
flags=1572864
;;
l|lock)
let flags+=16483
;;
*)
Usage 1
;;
esac
}
###
ChangeFlags()
{
flags=1572864
while read line; do
SumFlags ${line}
done <<< $( echo $1 | tr "," "\\n" )
hey -o "${app_name}" set Flags of Window "${win_ID}" to ${flags}
}
###
ToggleActive()
{
case $1 in
1|t|true|on|y|yes)
hey -o "${app_name}" set Active of Window "${win_ID}" to true
;;
0|f|false|off|n|no)
hey -o "${app_name}" set Active of Window "${win_ID}" to false
;;
toggle)
active=`hey -o "${app_name}" get Active of Window "${win_ID}"`
[ "${active}" == "true" ] && ToggleActive 0 || ToggleActive 1
;;
*)
Usage 1
;;
esac
}
###
ToggleMinimize()
{
case $1 in
1|t|true|on|y|yes)
hey -o "${app_name}" set Minimize of Window "${win_ID}" to true
;;
0|f|false|off|n|no)
hey -o "${app_name}" set Minimize of Window "${win_ID}" to false
;;
toggle)
minimized=`hey -o "${app_name}" get Minimize of Window "${win_ID}"`
[ "${minimized}" == "true" ] && ToggleMinimize 0 || ToggleMinimize 1
;;
*)
Usage 1
;;
esac
}
###
AbsPositionIt ()
{
hey -o "${app_name}" let Window "${win_ID}" do MoveTo BPoint[$1]
}
###
RelPositionIt ()
{
hey -o "${app_name}" let Window "${win_ID}" do MoveBy BPoint[$1]
}
###
PeekDesktop ()
{
[ -z ${dt_frame} ] && dt_frame=$((hey Tracker get Frame of Window 0 | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s,",$0}' ; echo -n ${db_frame}) | awk '{\
if (($5!=0) && ($7==$3 )) {print "0","0",$5,$4};\
if (($5==0) && ($7!=$3)) {print $7,"0",$3,$4};\
if (($7-$5)==($3-$1)) {if ($6!=0) {print "0","0",$3, $6}\
else {print "0",$8,$3,$4}}\
}' FS="," OFS=",")
}
###
PeekDeskbar ()
{
db_frame=$(hey Deskbar get Frame of Window 0 | awk '/result/{sub(/^.*\(/,"");sub(/\)/,"");gsub(" ","");printf "%s",$0}')
}
###############
# main script #
###############
script_name="$(basename ${0})"
db_frame="0,0,0,0"
if [ $# -ne 0 ]
then
while getopts "Da:dhlfs:t:w:L:F:p:P:n:m:H:r:M:A:G:" script_opt
do
case ${script_opt} in
D)
Discovery
;;
a)
app_name="$OPTARG"
;;
l)
[ -n "${app_name}" ] && EnlistWindows
;;
s)
[ -n "${app_name}" ] && win_ID="$OPTARG" || Usage 1
;;
P)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && AbsPositionIt "$OPTARG"
else
Usage 1
fi
;;
p)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && RelPositionIt "$OPTARG"
else
Usage 1
fi
;;
d)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
PeekDeskbar
else
Usage 1
fi
;;
m)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && PlaceOnEdges "$OPTARG"
else
Usage 1
fi
;;
H)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && SplitOnEdges "$OPTARG"
else
Usage 1
fi
;;
f)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
FullScreen
else
Usage 1
fi
;;
t)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ChangeTitle "$OPTARG"
else
Usage 1
fi
;;
w)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && SetWorkspace "$OPTARG"
else
Usage 1
fi
;;
r)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ResizeFrame "$OPTARG"
else
Usage 1
fi
;;
L)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ChangeLook "$OPTARG"
else
Usage 1
fi
;;
F)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ChangeFeel "$OPTARG"
else
Usage 1
fi
;;
n)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && SplitOnThirds "$OPTARG"
else
Usage 1
fi
;;
G)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ChangeFlags "$OPTARG"
else
Usage 1
fi
;;
A)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ToggleActive "$OPTARG"
else
Usage 1
fi
;;
M)
if [ -n "${app_name}" ] && [ -n "${win_ID}" ] ; then
CheckArgs "$OPTARG"
[ $? -ne 1 ] && ToggleMinimize "$OPTARG"
else
Usage 1
fi
;;
h)
Usage 0
;;
*)
Usage 1
;;
esac
done
else
Usage 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment