Help me to turn this Javascript to the Hazel system

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

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?
Dellu
 
Posts: 17
Joined: Thu Dec 12, 2013 6:26 am

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.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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.
Dellu
 
Posts: 17
Joined: Thu Dec 12, 2013 6:26 am

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?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion