# \[idea\] Pyradio quake like . .

**URL:** https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403
**Category:** Scripts, Tutorials & Tips
**Created:** [June 20, 2023, 7:10pm UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403 "2023-06-20T19:10:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [June 20, 2023, 7:10pm UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/1 "2023-06-20T19:10:01Z")

</div>

Hi @napcok,

What do you think about the following.

> To give Pyradio Guake behavior. [W+r]

#### Why …

It is quieter and quick way to use the radio.  
It prevents opening a new Pyradio instance every [W+r].

_gif_  
[![pyradio-quake-WR](https://forum.maboxlinux.org/uploads/default/original/2X/4/4f5ee61496ebc1fdd220f5b1a0156bfdc42cf3b0.gif)](https://ibb.co/09FQMFQ)

#### I got it to work, ugly for now . . . .

_What happend_

- I am not getting out of the position management, as you set it up.

- In my .config/mabox, i can’t see a file created for dimensions. (.quake-pyradio in my case).

- Using the ${HEIGHT}x etc lines, gives me only the terminal. No pyradio.

* * *

**As you can see, that’s why I put down the position fixed, for now.**

### mb-pyradio.sh (mabox-terminal)

```auto
#!/bin/bash

# Author: Daniel Napora <napcok@gmail.com>
# "Show-Hide" terminal wrapper for terminator for use with keybind eg. super + enter.
# Depenging on actual state it will start, show or hide terminal window.

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
NAME="pyradio"

__run() {
ID=$(wmctrl -x -l | grep ${NAME} | awk '{print $1}' | head -n 1)
if [-z "${ID}"]; then
    if [-f "$GEOMETRY_FILE"]; then
    POS=$(head -n 1 $GEOMETRY_FILE)
    terminator -T ${NAME} -b --geometry "$POS" -e 'pyradio -lt'
    else
	#TOP=$(wmctrl -d|grep "*"|awk '{print $8}'|cut -d',' -f2)
	#LEFT=$[$(wmctrl -d|grep "*"|awk '{print $4}'|cut -d'x' -f1)/8]
	#HEIGHT=$[$(wmctrl -d|grep "*"|awk '{print $4}'|cut -d'x' -f2)/2]
	#WIDTH=$[${LEFT}*6]
	#terminator -T ${NAME} -b --geometry ${WEIDTH}x${HEIGTH}+${LEFT}+${TOP} -e "pyradio -lt"
	
        terminator -T ${NAME} -b --geometry "900x400+150+48" -e 'pyradio -lt'
        
    fi
else
	ID_DEC=$((${ID}))
	ACTIVE_WIN_DEC=$(xdotool getactivewindow)
	if ["${ACTIVE_WIN_DEC}" == "${ID_DEC}"]; then
		xdotool windowminimize ${ID_DEC}
	else
		xdotool windowactivate ${ID_DEC}
	fi
fi
}

__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool getactivewindow))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE

}
__reset() {
    rm -f $GEOMETRY_FILE
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac

```

Curious what you think of the idea **- Pyradio quake like -**

🐦

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [June 21, 2023, 8:27pm UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/2 "2023-06-21T20:27:55Z")

</div>

Hi @muzqs  
I modified script a little, now saving position should work.

I also added --icon and removed -b (borderless - no window decoration option)

```auto
#!/bin/bash

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
NAME="quakeradio"

__run() {
ID=$(wmctrl -x -l | grep ${NAME} | awk '{print $1}' | head -n 1)
if [-z "${ID}"]; then
    if [-f "$GEOMETRY_FILE"]; then
    POS=$(head -n 1 $GEOMETRY_FILE)
    terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "$POS" -e 'pyradio -lt'
    else
       terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "900x400+150+48" -e 'pyradio -lt'
    fi
else
	ID_DEC=$((${ID}))
	ACTIVE_WIN_DEC=$(xdotool getactivewindow)
	if ["${ACTIVE_WIN_DEC}" == "${ID_DEC}"]; then
		xdotool windowminimize ${ID_DEC}
	else
		xdotool windowactivate ${ID_DEC}
	fi
fi
}

__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool search --name ${NAME}))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE
}
__reset() {
    rm -f $GEOMETRY_FILE
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac

```

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [June 23, 2023, 8:42am UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/3 "2023-06-23T08:42:10Z")

</div>

Hi @napcok,

Thanks for taking the time looking at the script.

> [@napcok](#):
>
> I also added --icon and removed -b (borderless - no window decoration option)

👌

* * *

#### A check thingy.

> Is it **True|False** that `.quakeradio` is needed to be created **manually**.

Once I manually create the file `.quakeradio` with a line like this, **900x400+150+48** , then  
the positioning works. `$POS`

If `.qaukeradio` [$GEOMETRY\_FILE] does not exist, it is also not created during the process.

_Actually i never saw `.quake-term` or` .quakeradio` file automatic generated._

```auto
__save() {
  eval $(xdotool getwindowgeometry --shell $(xdotool search --name ${NAME}))
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > $GEOMETRY_FILE
}

```

Without `.quakeradio` the dimensions are `top, left`, not using the `else`.

```auto
else
    terminator -T ${NAME} --icon=/usr/share/icons/pyradio.png --geometry "900x400+150+48" -e 'pyradio -lt'
    fi

```

* * *

#### 😵‍💫 I guess I don’t understand how the `$GEOMETRY_FILE` part works. 😵‍💫

Once I have manually edit `.quakeradio`, it works very nicely.

_Very happy with `W+r` now._🐦

---

<div class="post-metadata">

### Author: ![napcok](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/napcok/32/410_2.png) [@napcok](https://forum.maboxlinux.org/u/napcok)
#### Post date: [June 23, 2023, 8:56am UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/4 "2023-06-23T08:56:26Z")

</div>

> [@muzqs](#):
>
> Actually i never saw `.quake-term` or` .quakeradio` file automatic generated.

It is not automatically generated.  
You need to run command:

```auto
your_scriptname save

```

to generate it.

---

<div class="post-metadata">

### Author: ![M0nst3r](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/m0nst3r/32/1669_2.png) [@M0nst3r](https://forum.maboxlinux.org/u/M0nst3r)
#### Post date: [July 10, 2023, 6:44pm UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/5 "2023-07-10T18:44:59Z")

</div>

Same script with some minor improvements, hope you don’t mind 😉

```auto
#!/bin/bash

GEOMETRY_FILE="$HOME/.config/mabox/.quake-pyradio"
PYRADIO_ICON_FILE="/usr/share/icons/pyradio.png"
NAME="quakeradio"

__run() {
ID=$(wmctrl -xl | awk -v P="${NAME}" '$0 ~ P {print $1;exit}')
if [-z "${ID}"]; then
   if [-f "$GEOMETRY_FILE"] && [-s "$GEOMETRY_FILE"]; then
      POS="$(head -n 1 "$GEOMETRY_FILE")"
   else
      POS="900x400+150+48"
   fi
   terminator -T ${NAME} --icon="${PYRADIO_ICON_FILE}" --geometry "$POS" -e 'pyradio -lt'
else
   ID_DEC="$((${ID}))"
   ACTIVE_WIN_DEC="$(xdotool getactivewindow)"
   if ["${ACTIVE_WIN_DEC}" == "${ID_DEC}"]; then
      xdotool windowminimize ${ID_DEC}
   else
      xdotool windowactivate ${ID_DEC}
   fi
fi
}

__save() {
  eval "$(xdotool getwindowgeometry --shell "$(xdotool search --name ${NAME})")"
  echo "${WIDTH}x${HEIGHT}+${X}+${Y}" > "$GEOMETRY_FILE"
}
__reset() {
    rm -f "$GEOMETRY_FILE"
}

case "$1" in 
    save) __save;;
    reset) __reset;;
    *) __run;;
esac

```

---

<div class="post-metadata">

### Author: ![M0nst3r](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/m0nst3r/32/1669_2.png) [@M0nst3r](https://forum.maboxlinux.org/u/M0nst3r)
#### Post date: [July 10, 2023, 6:56pm UTC](https://forum.maboxlinux.org/t/idea-pyradio-quake-like/1403/6 "2023-07-10T18:56:03Z")

</div>

**Notes** :

- Files in variables; clear and easier to customize later on.
- Simplified method for getting the ID.
- Avoid a possible _race condition_ where the Geometry File may exists but it is empty.
- I was trying to get rid of the number format converting line but, surprisingly, none of the commands has a native way to do so. 😵‍💫
