Can't find a real solution for this, but there's a workaround if you can live with one extra space in your hardstatus line: make your script run in two modes, based on a command line argument.
- In checking mode, echo only a space when you want the color changed (e.g. when the disk is full).
- In normal mode, echo the free space or fill rate you want displayed.
Then you can do something like this in your .screenrc:
backtick 1 1 1 /tmp/script.sh check
backtick 2 1 1 /tmp/script.sh normal
hardstatus alwayslastline "%?%1`%{r}%: %?%2`"
The idea is to use the else (%:) clause to always output the same number of characters so the status line doesn't jump around, and use two invocations of the script (one to get the color optionally changed, one to print the actual value to display).
I tested this with this script, just to make sure it works:
#! /bin/bash
secs=$(date +%s)
if [ "${1:-check}" = "check" ] ; then
if (( $secs % 2 == 0 )) ; then
echo " "
fi
exit 0
fi
echo $secs
With that, the hardstatus line gives the current time (in seconds since 01/01/1970, very practical...) in red for even seconds, or in normal color for odd seconds.