5

So I have a hack to get my emacs org-clock to display in polybar (a system panel utility). It involves a script that looks like this:

CLOCKSTRING=`emacsclient --eval "(if (org-clocking-p)(print (org-clock-get-clock-string))(print -1))))"`

if [[ $CLOCKSTRING = "-1" ]]
then
        echo "Off-clock!"
else
        echo $CLOCKSTRING | cut -d\" -f2
fi

The problem is that print apparently prints to both the output of the commandline command (where I want it) and to a buffer in emacs (where I don't want it. When I'm working in emacs, I just see a window pop up that says the output of this command all the time, i.e. "-1 -1 -1 -1". How do I get print to print only to the command line?

Drew
  • 77,472
  • 10
  • 114
  • 243
Jonathan
  • 597
  • 5
  • 22

2 Answers2

1

When Emacsclient evaluates an expression, it's evaluated in a “normal” Emacs context. Standard output goes to its normal destination, which is the echo area. It doesn't go to Emacsclient. What you see in Emacsclient is the return value. So drop the print.

CLOCKSTRING=`emacsclient --eval "(if (org-clocking-p) (org-clock-get-clock-string) -1)"`
0

Your problem might be that your S-expression is unbalanced (two extra parentheses at the end).

This emacsclient --eval '(if (org-clocking-p)(print (org-clock-get-clock-string))(print -1))' returns -1 on the command line for me.