One thing I have learned while writing Bash scripts (for the hell of it sometimes) is that 'grep -q' is useful for direct use in 'if' expressions.

You could do:

if wmctrl -l | grep -q "LibreOffice"; then
   wmctrl -a "LibreOffice"
else
   loffice &amp;
fi

It can reduce script complexity a fair bit.