whitehouse Posted August 20, 2004 Posted August 20, 2004 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?
Fenton Posted August 21, 2004 Posted August 21, 2004 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
Fenton Posted August 21, 2004 Posted August 21, 2004 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
whitehouse Posted August 23, 2004 Author Posted August 23, 2004 Fenton, Thanks for your reply. I am using the script without error reporting, and it is working perfectly.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now