Commands like pgrep / ps / pidof doesn't return anything

script error

Add the line at the top of your script to catch everything

#!/usr/bin/env bash
set -ouxe pipefail

check your spelling and your variable assignment and subsequent reference

Thanks, but the missing output happens even if executed directly from the terminal (not inside the script).

However, I do get output from pgrep -f ardour6

computers are stupid - they answer your question - if you don’t get the answer you want - you asked the wrong question.

rephrase your command - use something more generic to find what the process name really is.

and you have supplied way too little information so answers are fluffy at best

Share your script here.

Didn’t really get the script started yet as I stumbled just determining if Ardour is running…

It 's supposed to look something like


 # check if Ardour is running
  pgrep ardour >/dev/null
  # check if presentation mode is off
# switch on Presentation Mode
  xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -T

…but like I said, running pgrep ardour from terminal returns nothing, while e.g. pgrep firefo returns the pid of firefox (even when misspelling like here).

Try now:

pgrep ardour >/dev/null

if [[ $? -eq 0 ]]
    xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/presentation-mode -T
    notify-send "ardour is not running!"

Make sure this script is executable:

chmod +x ./path_to_script

BTW You can also bind the xfconf-query -c xfce4-power.... command directly to a keyboard shortcut. That way it would be much easier to toggle it on or off when needed.

Thanks a lot! This is a pointer in the right direction, and running the script while Ardour is not running nicely outputs “ardour is not running” to notifications.

BUT, the output is the same WITH Ardour running, because the stumbling stone remains:

While pgrep firefox does return a pid, pgrep ardour returns nothing

It seems this will be an easier solution. Thanks again!

My computer answers the question pgrep firefox, giving the pid of firefox as expected.

My computer doesn’t answer the question pgrep ardour, giving nothing.

Can you help identifying how the second question is wrong?

There is nothing wrong. It just means that there is no process that is named ardour or contains this word.

Try with pgrep ArdourGUI.

But yet the program “Ardour” is runnning. Task Manager identifies it as Ardour. Granted, if started by commandline I have to type ardour6 but it shouldn’t matter much?

After all pgrep firefo (note the missing x) returns the pid of Firefox.

If the Ardour process is not named with anything like Ardour, then that is rather surprising. If it is so, how do I identify the correct name?

By the way, questions like pgrep xfce4-taskmanager and pgrep cadence are also answered with nothing.

Still nothing
EDIT: Missed the case sensitivity. It DOES find the pid, thanks.

It’s case sensitive. Just check your processes with ps aux for example and look at the name of ardour.

You need to find out the name of the process use for example the ps program. Read the man page for options.

By default pgrep is case sensitiv. So a “a” is not the same as a “A”. You might want to try the -i option.

Thanks, I missed that. pgrep ArdourGUI does return the pid of Ardour

This is working, thanks a lot! I’m still interested in making a few adjustments, continuing that mission on the other thread.

You see - that’s what I meant - if the answer you get is not the answer you want - you need to rephrase your question.

OK… man pgrep. And there’s a line towards end of file: “The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Use the -f option to match against the complete command line, /proc/pid/cmdline.”

So the name xfce4-taskmanager is too long for pgrep to find unless used with the option -f. Same option finds Cadence as well, which turns out to be a Python process.

Note to self: RTFM.