1

I want to use yad system tray notification to terminate an application (vlc for example), I used the following code:

yad --notification --no-middle --image=emblem-warning --menu='Cancel ! kill $pid' --text="My Tooltip" &

vlc & pid=${!}

The code gives the following error:

kill: failed to parse argument: '$pid'

any help is appreciated

muru
  • 207,228

2 Answers2

1

Run vlc first to get its PID correctly into the variable $pid like so:

vlc & pid=${!}

Then use double quotes " around the parameter(not single quotes ') to allow parameter expansion of $pid like so:

yad --notification --no-middle --image=emblem-warning --menu="Cancel ! kill $pid" --text="My Tooltip" &
Raffa
  • 34,963
0

The goal of the code is to launch ffmpeg to resize and encode a video and be able to close it using yad. I found the solution by storing the PID of the process in a temporary file. I spent long time trying to use single quotes inside bash -c 'command'. I finally solved it by replacing single quotes with '"'"'

export TMP="$(mktemp)"
yad --notification --no-middle  --command="" --image=emblem-warning --menu='Cancel current job ! bash -c "kill  $(cat $TMP); rm $TMP;"' & pid=$!
export fname="video.mp4"
bash -c 'echo $$>$TMP; exec ffmpeg -n -loglevel warning -i "$fname" -acodec copy -vcodec libx264 -crf 24 -vf "scale='"'"'if(gte(iw,ih),-1,720)'"'"':'"'"'if(gte(iw,ih),720,-1)'"'"'"  "${fname%%.*}_720.${fname##*.}"'
kill $pid
karel
  • 122,292
  • 133
  • 301
  • 332