We have a script that we’ve been using for a year or so that we’re now trying to improve upon. The script is run as a PDF Service from the Print dialog in FileMaker. It takes the PDF output of the print job, prompts the user for the recipient info, subject line, and body text, then sends it to Mail.app as a new message and sends. I’ve updated it to simply send the PDF output to Mail.app as an attachment to a new message with the idea that users are less likely to screw up the recipient’s address if they use Mail’s autocomplete and Address Book integration, rather than a plain old dialog.
Our FileMaker guy wants to populate the subject field with data from FileMaker. He has scripted FileMaker to put the appropriate data on the clipboard but I need to get it from there to the subject field.
My AppleScript kung-fu is pretty weak and I’m having a lot of trouble getting it to work. The script below generates the error: “Can’t make contents of clipboard into type reference.”
Any help would be greatly appreciated.
on open these_items
try
set this_file to item 1 of these_items
tell application "Finder"
set the file_name to the name of this_file
set the parent_folder to (the container of this_file) as alias
end tell
tell application (path to «constant afdregfp» as string)
set theSubject to clipboard
repeat
display dialog "Enter a name for file:" default answer file_name
set this_name to the text returned of the result
if this_name is not "" then exit repeat
end repeat
end tell
tell application "Finder"
set the name of this_file to this_name
set the target_file to ¬
(document file this_name of the parent_folder) as alias
end tell
tell application "Mail"
activate
set the new_message to ¬
(make new outgoing message with properties ¬
{subject:theSubject, visible:true, content:" "})
tell the new_message
tell content
make new attachment with properties ¬
{file name:target_file} at ¬
before the first character
end tell
end tell
end tell
on error error_message number error_number
if the error_number is not -128 then
tell application (path to «constant afdregfp» as string)
display dialog error_message buttons {"OK"} default button 1
end tell
else
tell application "Finder" to delete parent_folder
end if
end try
end open