Bates numbering with Hazel and PDFpen 7

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

Moderator: Mr_Noodle

Bates numbering with Hazel and PDFpen 7 Tue Feb 10, 2015 2:01 pm • by tylat2165
I am trying to get Hazel to watch a folder, and when a PDF enters the folder, to run the PDF pen 7 Bates numbering AppleScript. However, when I embed the AppleScript into Hazel, and try to compile it, I get an error message. See the AppleScript below.

The error message says "expected 'end' but found 'on' ", and it points to the leading-zero subroutine (that begins after the 'on') as a problem.

Does anyone know how to make it work?

Note: I got the regular page numbering AppleScript from PDF pen 7 to work (as an embedded script), but I need the Bates numbering feature.

Thanks for any help you can offer. Ty.



*********BATES NUMBER SCRIPT FROM PDFPEN 7 ********
-- This script places a page number in the bottom left corner of each page using a bates numbering scheme.
tell application "PDFpenPro 7"
if (count documents) > 0 then

-- Get value for what should be prepended to beginning of numbering scheme.
set prepend_value to text returned of (display dialog ¬
"Enter Bates numbering prefix:" with title ¬
"Bates Numbering" default answer ¬
"" buttons {"Cancel", "OK"} ¬
default button "OK")

set pageCount to count (pages of document 1)
repeat with pageNumber from 1 to pageCount
set thePage to page pageNumber of document 1
set currentPage to prepend_value & my add_leading_zeros(pageNumber, 5) as rich text
make new text imprint at end of imprints of thePage with properties {rich text:currentPage, x position:36, y position:36, height:16, width:540}
end repeat
return pageCount
end if
end tell

-- A sub-routine for adding leading zeros to numbers:
-- Courtesy of Apple
-- http://www.apple.com/applescript/sbrt/sbrt-02.html
on add_leading_zeros(this_number, max_leading_zeros)
set the threshold_number to (10 ^ max_leading_zeros) as integer
if this_number is less than the threshold_number then
set the leading_zeros to ""
set the digit_count to the length of ((this_number div 1) as string)
set the character_count to (max_leading_zeros + 1) - digit_count
repeat character_count times
set the leading_zeros to (the leading_zeros & "0") as string
end repeat
return (leading_zeros & (this_number as text)) as string
else
return this_number as text
end if
end add_leading_zeros

***
***************************
tylat2165
 
Posts: 4
Joined: Tue Feb 10, 2015 1:35 pm

Re: Bates numbering with Hazel and PDFpen 7 Wed Feb 11, 2015 11:52 am • by Mr_Noodle
You might want to enclose the script in code tags to preserve the formatting. Also, as mentioned in email, you'll need to incorporate theFile variable to refer to the file being matched. As for the rest, I'm not familiar with how PDFPen Pro works so if others can chime in, that'd be great.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Bates numbering with Hazel and PDFpen 7 Mon Feb 16, 2015 12:57 am • by tylat2165
Thank God!! I got it to work. I had to use it as an external script and add the hazel handler. Let call this part 2 of the Hazel bate label rule.

Because when I ran it, it would bates any document I was working in or was already open, instead of the new document in the folder that I wanted it to bates number. So I set up part 1 of the Hazel rule .. . telling Hazel to open the document and bring it to the front.

After that happened, it would bates number just fine. Whew! Hope this help save someone else the several days it took me to figure this out! God bless :-)

Code: Select all
-- Added Hazel handler to pdfpen7 script. Begins here.
on hazelProcessFile(theFile)
   
   -- This script places a page number in the bottom left corner of each page using a bates numbering scheme.
   tell application "PDFpenPro 7"
      if (count documents) > 0 then
         
         set pageCount to count (pages of document 1)
         repeat with pageNumber from 1 to pageCount
            set thePage to page pageNumber of document 1
            set currentPage to my add_leading_zeros(pageNumber, 5) as rich text
            make new text imprint at end of imprints of thePage with properties {rich text:currentPage, x position:510, y position:36, height:16, width:540}
            --changing pdfpens's default x position above from 36 to 510, to move number to bottom right instead of bottom left
         end repeat
         return pageCount
      end if
   end tell
end hazelProcessFile
-- End of Hazel Handler

-- A sub-routine for adding leading zeros to numbers:
-- Courtesy of Apple
-- http://www.apple.com/applescript/sbrt/sbrt-02.html
on add_leading_zeros(this_number, max_leading_zeros)
   set the threshold_number to (10 ^ max_leading_zeros) as integer
   if this_number is less than the threshold_number then
      set the leading_zeros to ""
      set the digit_count to the length of ((this_number div 1) as string)
      set the character_count to (max_leading_zeros + 1) - digit_count
      repeat character_count times
         set the leading_zeros to (the leading_zeros & "0") as string
      end repeat
      return (leading_zeros & (this_number as text)) as string
   else
      return this_number as text
   end if
end add_leading_zeros
tylat2165
 
Posts: 4
Joined: Tue Feb 10, 2015 1:35 pm

Re: Bates numbering with Hazel and PDFpen 7 Mon Feb 16, 2015 1:07 am • by tylat2165
tylat2165
 
Posts: 4
Joined: Tue Feb 10, 2015 1:35 pm

Re: Bates numbering with Hazel and PDFpen 7 Mon Feb 16, 2015 12:32 pm • by Mr_Noodle
I think it might be working by coincidence in that the file you want to process happens to be open. You probably should be incorporating "theFile" into the script to make it more consistent. Like have PDFPen open "theFile" or somesuch to ensure that the file is open for the rest of the script to work.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Bates numbering with Hazel and PDFpen 7 Mon Feb 16, 2015 1:15 pm • by tylat2165
Thanks P, I'll try that!
tylat2165
 
Posts: 4
Joined: Tue Feb 10, 2015 1:35 pm

Re: Bates numbering with Hazel and PDFpen 7 Mon Jun 01, 2020 7:22 am • by Boogie2
Thanks for this. I use PDFPenPro and also DEVONthink Pro Office for OCR. Does anyone know which has the better OCR engine? Thanks.
if you want to use your whatsapp with some extra feature and functions then FMWhatsapp is available
Boogie2
 
Posts: 1
Joined: Mon Jun 01, 2020 7:19 am

I am having a issue with Hazel and PDFPEN 7 and I am here to solve does any one help me to solve the issue?

or

will I have to make a new thread for my issue with Hazel and PDFPEN 7?
Best regards mini militia

Ethan Miles

check this gb whatsapp
ethanmiles
 
Posts: 2
Joined: Wed Jan 12, 2022 10:58 am

Re: Bates numbering with Hazel and PDFpen 7 Tue Jan 18, 2022 12:32 pm • by Mr_Noodle
Please post a new topic and provide more details.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Please post a new topic and provide more details.

Thanks for your reply :)
Best regards mini militia

Ethan Miles

check this gb whatsapp
ethanmiles
 
Posts: 2
Joined: Wed Jan 12, 2022 10:58 am


Return to Support