Score:1

How to use yad to terminate application

in flag

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

Score:1
jp flag

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" &
Mahmoud Alnaanah avatar
in flag
Thanks for your reply.
NotTheDr01ds avatar
vn flag
@MahmoudAlnaanah Unless I'm mistaken, Raffa's answer solved the error in your question. The other changes that you made to your script (in your answer) don't seem to have to do with the error that you were receiving. I would recommend marking this as the accepted answer. Thanks!
Score:0
in flag

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
NotTheDr01ds avatar
vn flag
A few notes on your answer -- First, you'll notice that muru took the time to edit your question to improve the formatting and readability. We're happy to do that the first time for you as you get used to site, but we're also hoping that you'll use the example to improve the formatting of your future posts, rather than making the same mistakes again. In this case, your answer has the same formatting issues as your question.
NotTheDr01ds avatar
vn flag
Second the suggestion to use double-quotes in place of the single-quotes came from [@Raffa's answer](https://askubuntu.com/a/1449290/1165986) shortly after you posted the question. When you post an answer, we do require that you provide proper attribution for any part of the answer that you didn't come up with yourself.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.