Newbie question about automating printing

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

Moderators: Mr_Noodle, Moderators

Newbie question about automating printing Fri Aug 09, 2013 6:27 pm • by Kevin L.
I've got a custom folder action script a developer wrote for me to watch for new folders being added to a directory and then open the enclosed html files and print them through Safari. It works great when the folder action scripts are choosing to work, but they randomly stop working and I have no idea why.

I stumbled across Hazel and wondered if there's a way to open html files, then print them in Safari. The code I'm using right now for the folder action script looks like this:
Code: Select all
# Watch reportFolder for added items.
on adding folder items to thisFolder after receiving newOrderFolders
   #say "added"
   
   # Loop on each added item
   repeat with i from 1 to number of items in newOrderFolders
      try
         # Get our orderFolder and orderFolderPath
         set orderFolder to item i of newOrderFolders
         set orderFolderPath to orderFolder as text
         
         # Get the orderNumber using finder
         tell application "Finder"
            set orderNumber to name of orderFolder
         end tell
         
         # Set jobSheet
         set jobSheet to orderFolderPath & orderNumber & "_ACPJobSheet.html"
         delay 2
         #display alert "Job sheet " & jobSheet
         
         # Open safari and print
         tell application "Safari"
            activate
            open jobSheet
            delay 2
            print document 1 with properties {copies:1} without print dialog
            close (every window whose name is "Aspen Creek Photo Job Sheet")
         end tell
         
      on error errText number errNum
         display dialog "Error printing order sheet: " & jobSheet & "[" & errNum & return & errText & "]"
      end try
      #say "done with " & i
      
   end repeat
   
end adding folder items to


Is this even possible with Hazel? Or, could I just modify my folder action script above and use Hazel to trigger it instead of relying on the Finder? Thanks!
Kevin L.
 
Posts: 1
Joined: Fri Aug 09, 2013 6:19 pm

Please do not post questions in the Tips forum. The sticky article up top states that you shouldn't do this. That forum is for providing tips, not asking for them.

Hazel doesn't have this built-in so you'd need to have Hazel trigger the AppleScript. Search the help for AppelScript as you have to structure your script a certain way for it to work.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Open Discussion