PDF attached to mail without dialog

Today, I've been working on a database that sends reminders to users and in the script on the server but called from a robot file running on a Mac. It's to save the file as a PDF, then attach it to the email and then send. It works perfectly if I use the dialog, but without the dialog, no pdf is attached. Can anyone tell me why or a work around? I'd like the script to run automatically called from the robot file and send from a local mail account in mail.app. I would appreciate anyone's help.

You have to give time for the OS to catch up with the fact that the pdf exists. Insert a pause in your script between saving the pdf and creating the email. Try a very short pause (1 second, say) and increase it if needed.