Help to Get HAZEL to run script then move both files

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

Moderator: Mr_Noodle

I really tried! Over & Over again!

I down loaded the trial version. If I can get this to work for my company they will buy several versions.

But I can not figure out how to get HAZEL to run the script! I think this is probably easy but I can not figure it out!!!! I did read Hazel help on working with scripting but still not sure what to do? I am completely new to scripting.


I would like HAZEL to run the script below on one file at a time,
The script below opens any .ai Illustrator file to save as a .pdf then opens the .pdf in Acrobat Pro to "Enable Commenting & Measuring..."

THEN I need HAZEL to move both finished .ai & new converted .pdf files (When script is done) to certain folders based on the first 6 characters of the name.

Example any files starting with "ILCJ54.ai" & "ILCJ54.pdf" would be moved to folder "C520-13 CJ54" Plus any files
"ILDG93.ai" & "ILDG93.pdf" would be moved to folder "CD4.1-14 DG93" & so on.

I would need HAZEL to work from one script so that when I add or subtract from the script their will only be one script to edit. So I think that the "For external scripts" option is what would do this.

Code: Select all
-- fileList is a list of aliases to Illustrator files
-- destFolder is an alias to a folder where PDF files are saved
on SaveFilesAsPDF(fileList, destFolder)
   set destPath to destFolder as Unicode text
   repeat with aFile in fileList
      tell application "Finder" to set fileName to name of aFile
      set newFilePath to destPath & fileName
      tell application "Adobe Illustrator"
         open aFile
         save current document in file newFilePath as pdf with options {class:PDF save options, acrobat layers:false, compatibility:Acrobat 8, preserve editability:false, font subset threshold:0.0}
         close current document saving no
      end tell
      my process_documents()
   end repeat
end SaveFilesAsPDF
-- Call handler
set sourceFolder to "Macintosh HD:Users:Dave:Desktop:Illustrator:"
tell application "Finder" to set fileList to every file of folder sourceFolder -- "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" as alias list
set destFolder to "Macintosh HD:Users:Dave:Desktop:PDF:"
SaveFilesAsPDF(fileList, destFolder)

--tell application "Finder" to set theFiles to every document file of folder "Macintosh HD:Users:b3po:Public:AI to PDF to Enabled" whose file type ends with "ai"

on process_documents()
   tell application "System Events"
      try
         tell process "Acrobat"
            -- bring acrobat to the front
            set frontmost to true
            set windowName to value of static text 1 of window 1
            -- select the enable commenting menu item
            try
               -- Acrobat Pro 9
               click menu item "Enable for Commenting and Analysis in Adobe Reader..." of menu 1 of menu bar item "Comments" of menu bar 1
            on error
               -- Acrobat Pro X
               try
                  -- OS X Snow Leopard
                  click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
               on error
                  -- OS X Lion
                  click menu item "Enable Commenting & Measuring..." of menu 1 of menu item "Reader Extended PDF" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
               end try
            end try
            
            -- change save as filename
            -- wait until save dialog is opened
            set saveDialogActive to false
            repeat until saveDialogActive is true
               try
                  set fileName to value of text field 1 of window "Save As"
                  set saveDialogActive to true
               on error
                  set saveDialogActive to false
               end try
            end repeat
            
            set value of text field 1 of window "Save As" to fileName
            -- save file
            click button "Save" of window "Save As"
            if exists sheet 1 of window "Save As" then
               click button "Replace" of sheet 1 of window "Save As"
            end if
         end tell
      end try
   end tell
   
   -- stop processing until window is closed
   set windowActive to true
   repeat until windowActive is false
      tell application "System Events"
         try
            tell process "Acrobat"
               -- bring acrobat to the front
               set frontmost to true
               -- close file
               click button 1 of window windowName
               set windowName to value of static text 1 of window 1
            end tell
         on error
            set windowActive to false
         end try
      end tell
   end repeat
end process_documents


Please, does anyone know how to get this to work? I would be so thankful!!

Computer info:
Model: imac
AppleScript: 2.3
Browser: Safari 534.55.3
Operating System: Mac OS X (10.6)
brianedl
 
Posts: 26
Joined: Tue Jun 05, 2012 10:08 am

For external scripts, you need to use a specific handler. Please read the help on AppleScript.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Is there a similar example that you could show me? I have been trying to understand how to make any script run through HAZEL but with no success. I'm not sure what to do, even when over & over I think I have figured it out?
brianedl
 
Posts: 26
Joined: Tue Jun 05, 2012 10:08 am

Did you read the help? There's a template there which you can use. As for other examples, poke around the forums as people have posted a lot of scripts.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I've tried to over & over but just not understanding what I'm doing wrong! I've tried it with a simple script to just open the file & still when I drop a file in that folder the script does not run? Maybe I am just out of my league?!?
brianedl
 
Posts: 26
Joined: Tue Jun 05, 2012 10:08 am

brianedl wrote:I've tried to over & over but just not understanding what I'm doing wrong! I've tried it with a simple script to just open the file & still when I drop a file in that folder the script does not run? Maybe I am just out of my league?!?



Just to be clear, the "help" that mr_noodle is requesting that you read is the question mark button in the lower right hand corner of the prefpane.

It is very useful.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado


Return to Support