Shell and Apple script not working

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Shell and Apple script not working 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?
raxtor
 
Posts: 7
Joined: Fri Jul 18, 2008 10:03 am

Re: Shell and Apple script not working Wed Apr 26, 2023 8:43 am • by Mr_Noodle
Have you tried those scripts outside of Hazel?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Shell and Apple script not working 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.
raxtor
 
Posts: 7
Joined: Fri Jul 18, 2008 10:03 am

Re: Shell and Apple script not working 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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron