there is a non-zero chance that this could actually work on the first try

I have not yet tested it but it should provide a good basis for working from
This seems to give an error: /var/lib/xinit/functions: line 489: /tmp/fileZiUgVT: Permission denied
You're piping the output through a temp file? shoudln't you pipe it to an executable or something? maybe you want to > to that file?