Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7396 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I'm working on exporting my Filemaker layouts to pdf's so I can e-mail them. Since I'm not fond of getting a plugin, I'm relying heavily on applescript.

Right now, I have it setup so that the script exports the pdf to a "Quotes" folder on the users Desktop. I'm trying to rename the pdf with the following applescript.

 set newname to cell "Prospect ID" of current record

set filepath to (((path to desktop) as string) & "Quotes:temp_quote.pdf")

tell application "Finder"



if name of document file (((path to desktop) as string) & "Quotes:" & ((newname as string) & ".pdf"))exists then

		--do nothing

	else

		set name of document file filepath to ((newname as string) & ".pdf")

	end if

end tell 

I'm having a problem getting it to determine if the file its renaming to already exists. any ideas?

Posted

It's often dodgy using "exists", 'cause it kicks up an error if it doesn't exist. If you surround what you're trying with a "try" block, then it suppresses errors. It sort of depends on what the logic is, whether you want to trap for errors or not.

Also, the script wasn't happy with all the nested parentheses, perhaps trying to do too much at once. It's easier to set the long file paths into variables earlier, so it's simpler later. The following won't return an error, even if the temp file is missing entirely. Someone may have a better method, but this one's short :-)

set newname to cell "Prospect ID" of current record

set filepath to ((path to desktop as string) & "Quotes:temp_quote.pdf")

set newFile to ((path to desktop as string) & "Quotes:" & newname & ".pdf")

tell application "Finder"

try

if not (exists file newFile) then

set name of document file filepath to (newname & ".pdf")

end if

end try

end tell

Posted

With error messages:

set newname to cell "Prospect ID" of current record

set filepath to ((path to desktop as string) & "Quotes:temp_quote.pdf")

set newFile to ((path to desktop as string) & "Quotes:" & newname & ".pdf")

tell application "Finder"

try

if exists file filepath then

try

if not (exists file newFile) then

set name of document file filepath to (newname & ".pdf")

else

display dialog "The "" & newname & ".pdf" file is already there" buttons {"OK"} default button 1

end if

end try

else

display dialog "The "temp_quote.pdf" file is not there" buttons {"OK"} default button 1

end if

end try

end tell

This topic is 7396 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.