#!/usr/bin/zsh # License: GPLv3+ RES=('1280x1024' '1920x1200') if [[ -n ${1} ]]; then typeset -A RESMAP RESMAP=('02.150' '2' '02.133' '2') read -A ROOM <<< $(${HOME}/bin/cipmap.sh -l|grep ${USER}) # Note: Alter the number below such that it reflects the # position of the Room-ID in the cipmap.sh output # for your user; counting from right to left. ROOM=${ROOM[-2]} NEXT=${RESMAP[${ROOM}]} NEXT=${NEXT:-1} else read -A CURRENT <<< $(grep '*' - < <(xrandr)) CURRENT=${CURRENT[1]} for INDEX in {1..${#RES}}; do if [[ "${CURRENT}" == "${RES[${INDEX}]}" ]]; then if [[ ${INDEX} -lt ${#RES} ]]; then NEXT=$(( INDEX+1 )) else NEXT=1 fi break fi done; fi # Try to set new resolution. TRIES=1; RUN=1 while [[ ${TRIES} -lt 33 && ${RUN} -eq 1 ]]; do if xrandr -s ${RES[${NEXT}]} > /dev/null; then RUN=0; else print -- 'Error: Failed setting resolution!' print -- " Current: ${CURRENT} - Next: ${RESOLUTIONS[${NEXT}]}" sleep .1 (( TRIES++ )) fi done