August 20, 200421 yr 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?
August 21, 200421 yr 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
August 21, 200421 yr 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
August 23, 200421 yr Author Fenton, Thanks for your reply. I am using the script without error reporting, and it is working perfectly.
Create an account or sign in to comment