Newbie help with clipboard stuff

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

Try changing:

set theSubject to clipboard

to

set theSubject to clipboard as string

-N

Thanks for the reply.

I tried that and I get “Can’t make clipboard of application … into string” - regardless of the text on the clipboard.

try

Browser: Safari 125.12
Operating System: Mac OS X (10.3.8)

Perfect! Thank you.

Hi!

I see you use the AppleScript to send a mail. Could you help me? I also want ot send a mail with the Mail.
For example I would like to send the message to “xy@mail.com”, with the subject “Subjectblabla”, the message is “Messageblabla” , & theVariable, "blabla2 ", & theVariable, “blablabla3”.
Maybe it would be the best to write the message into the subject line. Does anybody know, how many characters you can write into it?

Browser: Safari 100
Operating System: Mac OS X (10.3.7)