Getting and setting screen size for Xorg

You can use xrandr to do both

Get resolution

$ xrandr
Screen 0: minimum 320 x 240, current 1920 x 1080, maximum 1920 x 1080
default connected 1920x1080+0+0 0mm x 0mm

Set resolution

$ xrandr --output default --mode 1280x1024

From my personal shell library:

get_screen_size()
{
    xdpyinfo | awk '/dimensions:/ { print $2; exit }'
}

Clean xrandr output for imagemagick use

The following line takes the output of xrandr and cleans it with awk for use with imagemagick:

$ xrandr |awk '$0 ~ "*" {print $1}'

1366x768