Help with clipboard to variable problem

Hi

The script is suppose to rename a generic pdf generated by my scanner to a specific name pulled from a FileMaker DB. I’ve got it working up to the line changing the name. If I plug in a any quote text it work fine but if I try to use the string on the clipboard it will fail to change the file name. Looking at the Events/Results the the proper string is there but the file name does not change. Here is the the part of the script that in question


tell application "FileMaker Pro"
	activate
	tell database "MedicalReciepts2011.fp7"
		do script "Get PDF Name"  -- gets value from field and puts it on the clipboard
	end tell
end tell

set theFolder to "Macintosh HD:Users:alanmcw:Documents:Personal:Privite:11 Med Files:PDFs:"

tell application "Finder" to set theFileName to (the clipboard) as string   --does not work
--tell application "Finder" to set theFileName to "test"  as string   --does work

tell application "Finder"
	set the name of the first file of the folder theFolder to theFileName & ".pdf"
end tell

Here is the Event/Reply using the clipboard…

If you switch lines 10 & 11 it works.

I’m sure I’m missing some thing really obvious but I’m just not seeing it.

Any help will be much appreciated

cheers
al

The only way I think that the script would run but the file name wouldn’t change is if the file name already exists in the folder eg. some other file already has that name. You can try coercing the new file to an alias as a quick check for the file. If the file already exists then you know you have a problem. If the file doesn’t the alias produces an error and that means it’s OK to use the new file name. So something like this would work.

NOTE: you do not need the Finder to get the clipboard contents.

tell application "FileMaker Pro"
	activate
	tell database "MedicalReciepts2011.fp7"
		do script "Get PDF Name"  -- gets value from field and puts it on the clipboard
	end tell
end tell

set theFolder to "Macintosh HD:Users:alanmcw:Documents:Personal:Privite:11 Med Files:PDFs:"

set theFileName to (the clipboard) as string --does not work
set newFileName to theFileName & ".pdf"

try
	alias file (theFolder & newFileName)
	display dialog "Error: the file name already exists in the folder."
on error
	tell application "Finder"
		set the name of the first file of the folder theFolder to newFileName
	end tell
end try