Page 1 of 1

Help me to turn this Javascript to the Hazel system

PostPosted: Sat Aug 28, 2021 8:08 am
by Dellu
I find the following script here:https://stackoverflow.com/questions/35001831/how-to-check-multiple-pdf-files-for-annotations-comments:

Code: Select all
this.syncAnnotScan();
var annots = this.getAnnots();
var fname = this.documentFileName;
fname = fname.replace(",", ";");
var errormsg = "";
if (annots) {
    try {
        this.saveAs({
            cPath: "/c/folder/"+fname,
            bPromptToOverwrite: false //make this 'true' if you want to be prompted on overwrites
        });
    } catch(e) {
        for (var i in e)
        {errormsg+= (i + ": " + e[i]+ " / ");}
        app.alert({
            cMsg: "Error! Unable to save the file under this name ('"+fname+"'- possibly an unicode string?) See this: "+errormsg,
            cTitle: "Damn you Acrobat"
        });
    }
;}
annots = 0;


it is very effective script.

What it does is identify annotated pdf files and moves them to a specific folder.

I want to use it inside hazel to tag pdf files which have annotations (rather than moving them to a specific folder.).

I tried to adopt it as follows:
Code: Select all
theFile.syncAnnotScan(); 
var annots = theFile.getAnnots(); 
if (annots==null || annots.length==0) return false;
else return true; 

But, I am not getting a result. I am not good with scripts. Can you help me please?

Re: Help me to turn this Javascript to the Hazel system

PostPosted: Mon Aug 30, 2021 10:33 am
by Mr_Noodle
Do you have a JavaScript interpreter installed on your machine? If not, you'll need to do that and then reference that as the shell in your Run ShellScript script.

Re: Help me to turn this Javascript to the Hazel system

PostPosted: Tue Aug 31, 2021 6:50 am
by Dellu
Mr_Noodle wrote:Do you have a JavaScript interpreter installed on your machine? If not, you'll need to do that and then reference that as the shell in your Run ShellScript script.

According to this: https://stackoverflow.com/a/10072393/3015087, every mac comes with Javascript interpreter.

After following the instruction & creating a symbolic link, I am trying the following:

Code: Select all
#! /bin/bash
annot = $(/usr/local/bin/jsc  $1.syncAnnotScan() var annots = $1.getAnnots();)
if  [ `/usr/bin/grep "annot" | grep Type | sed -n '$='` ]
then
exit 1
else
exit 0
fi


But, I am not getting a good result.

Re: Help me to turn this Javascript to the Hazel system

PostPosted: Tue Aug 31, 2021 10:14 am
by Mr_Noodle
I don't understand the syntax for calling jsc here so I can't be of much help there. How does it run in Terminal?