Page 1 of 1

Shell and Apple script not working

PostPosted: Tue Apr 25, 2023 12:17 pm
by raxtor
I'm using a script to add ebooks (ePub and PDFs) automatically to Calibre, using

Code: Select all
/Applications/calibre.app/Contents/MacOS/calibredb add "$1"


as an embedded shell script. This works fine. However, I wanted to add a condition to this rule that Calibre itself isn't running, as that will cause
Code: Select all
calibredb
to fail. I can't get that to work using either a shell script or an apple script.

I'm using the following embedded shell script as a rule condition:
Code: Select all
#!/bin/bash
PROCESS=calibre
number=$(ps aux | grep -v grep | grep -ci $PROCESS)

if [ $number -gt 0 ]
    then
        exit 1
   else
      exit 0
fi


This gives me a Rule does not match whether Calibre is running or not.

Using the following embedded Apple Script
Code: Select all
if application "calibre" is running then
   return false
else
   return true
end if


gives me an "Error evaluation condition":
Code: Select all
Error executing AppleScript: calibre got an error: Can’t get running.


Any hints?

Re: Shell and Apple script not working

PostPosted: Wed Apr 26, 2023 8:43 am
by Mr_Noodle
Have you tried those scripts outside of Hazel?

Re: Shell and Apple script not working

PostPosted: Tue May 02, 2023 11:57 am
by raxtor
Mr_Noodle wrote:Have you tried those scripts outside of Hazel?


Yup. Both work fine actually.

Re: Shell and Apple script not working

PostPosted: Wed May 03, 2023 9:02 am
by Mr_Noodle
At least for the AppleScript, have you given Hazel automation permissions to operate with calibre?

For the shell script, maybe you should print things out at various stages. If you turn on debug mode (https://www.noodlesoft.com/kb/hazel-debug-mode/), you can see the script output in the logs.