I need to create a script that I can bind to a keyboard shortcut. The script opens an instance of mozilla if it is not open and if is it minimizes or maximises the window. Kind of like drop down terminal.
The script is working when I open it from a desktop shortcut but if I open the script directly by clicking on it or macro it to a keyboard shortcut it doesn't work as expected. It only opens mozilla but doesn't minimize or maximize
#!/bin/bash
touch memory.txt
myvar="$( xdotool search Mozilla )"
status="$(grep [0-1] memory.txt)"
run=0
if [ $(grep -c [0-9] <<< $myvar) -gt 0 ]
then
pwd
else
(firefox &)
fi
if [ $status = 0 ]
then
$(xdotool windowminimize $myvar)
echo -n "1" > memory.txt
run=1
fi
if [ $status = 1 ] && [ $run -eq 0 ]
then
$(wmctrl -ia $myvar)
echo -n "0" > memory.txt
fi
exit