patri9ck / a2ln-server

A way to display Android phone notifications on Linux (Server)
GNU General Public License v3.0
99 stars 8 forks source link

Running a script file from --command option with references to {app} #19

Closed Ao1Pointblank closed 1 year ago

Ao1Pointblank commented 1 year ago

How can I pass the {app} variable to this script, in order to play custom sounds with each app's notifications?

• _a2ln_appsounds.sh:

#!/bin/bash
if [ -f "~/.sounds/a2ln/{app}.mp3" ]; then
    play -q "~/.sounds/a2ln/{app}.mp3"
else
    play -q "~/.sounds/a2ln/default_notif.mp3"
fi

executed by: a2ln --pairing-port 46351 --title-format "{app} | {title}" 46352 --command "bash -c ~/.sounds/a2ln/a2ln_app_sounds.sh"

Ao1Pointblank commented 1 year ago

Aha! I got what I needed by using a 1-line command instead of a script file. But is there a way {app}, {title} and {body} can be passed through an external script?

a2ln --pairing-port 46351 --title-format "{app} | {title}" 46352 --command 'if [ -f ~/.sounds/a2ln/{app}.mp3 ]; then play -q ~/.sounds/a2ln/{app}.mp3; else play -q ~/.sounds/a2ln/default_notif.mp3; fi'
patri9ck commented 1 year ago

Hey, thanks for the issue.

You can pass the app's name as an argument to the script.

#!/bin/bash
app=$1
if [ -f "~/.sounds/a2ln/${app}.mp3" ]; then
    play -q "~/.sounds/a2ln/${app}.mp3"
else
    play -q "~/.sounds/a2ln/default_notif.mp3"
fi
a2ln --pairing-port 46351 --title-format "{app} | {title}" 46352 --command "bash -c ~/.sounds/a2ln/a2ln_app_sounds.sh {app}"