Automatic "raw printing" script

Good morning to all. :smiley: This is my first post, my name is Fabio and I am a web developer.
Here’s my question. I have a text file, downloaded automatically by Safari, which must be printed directly on a printer, via lpr.
I configured some folder actions on the safari’s ‘download’ folder: when the file is downloaded on the folder, i execute " lpr -P xxx filename.txt " then rename it to filename_1.txt then move it to a backup folder.
This works but I need more control on this process.
A friend of mine suggested us to study how launchtl works. Can I bind to some folder-specific event and get the same job by using it? What AppleScript do I have to write to achieve my goal?

Thanks for your help. :cool:

When you say “I need more control of the process” you should explain more. We might be able to help you find the best solution. launchd can be configured to watch a folder however it’s only better at some things than an applescript folder action. For example, with a folder action you get the file or files that are added, with launchd you do not. launchd only gives you a notification that something happened in the watched folder but it doesn’t tell you what happened. So for your case where you need to act on the added file it seems the folder action is probably better however without knowing more it’s hard to say.