Skip to content

Instantly share code, notes, and snippets.

@somian
Last active August 29, 2015 14:15
Show Gist options
  • Save somian/b45b5cad4e04b15e5afb to your computer and use it in GitHub Desktop.
Save somian/b45b5cad4e04b15e5afb to your computer and use it in GitHub Desktop.
picture-window-scrape
#!/bin/bash
# picturewindowscrape
# Global:
SDIMS=2480x1600
# See if we are provisioned up.
for MYEXE in xvfb-run x11vnc vncviewer pstree pgrep
do if [[ -n $(which "$MYEXE") ]]
then :
else printf >&2 'Missing program: no "%s"' "$MYEXE"
exit 1
fi
done
xvfb-run -s "-screen 0 ${SDIMS}x24" -a $(which google-chrome-stable) \
--user-data-dir=/tmp/${USER.$(date -u '+%B%d'}/xvfb --start-fullscreen \
file:${HOME}/Public/I-KNOW-VAT.html
# check the PID, using pgrep:
QUUR=$(pgrep -l xvfb-run |cut -d ' ' -f 1)
# get the DISPLAY and XAUTH
pstree -Galp $QUUR |cut -d, -f 2- |grep -- -auth >/tmp/fusssh.101
1716 :99 -screen 0 ${SDIMS}x24 -nolisten tcp -auth /tmp/xvfb-run.NU2LGn/Xauthority
# LOOKS LIKE:
# 1716 :99 -screen 0 1600x1600x24 -nolisten tcp -auth /tmp/xvfb-run.NU2LGn/Xauthority
# WE WANT THE SECOND AND LAST FIELDS
TYE=$(perl -nae '@hoo = @F[1,$#F] ; printf ("%s %s", @hoo) if @hoo ==2' </tmp/fusssh )
DISPLAY=${TYE%" "*}
DISPLAY=${TYE%" "*} XAUTHORITY=${TYE#*" "} marco &
x11vnc -display $DISPLAY -bg -nopw -listen localhost -xkb &
sleep 3 && vncviewer -FullColor=1 localhost:5900 &
#--# Separate script:
# (now we have a window on the desktop running on xvfb)
# (navigate in chrome to the photo site and pull up the image we want)
# XAUTHORITY=/tmp/xvfb-run.GDzRJ0/Xauthority import -window root -display :99 [filename destination.png]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment