Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Renaming a file via AppleScript from FMP

Featured Replies

I have a problem with printing from an FMP script to .ps or .pdf because FMP doesn't remember the name of the output file. To get around this, I have been looking at the archives of this list and someone mentioned what is my script below, but I cannot get it to work. I get a message something like: "Finder got an error: Can't set file "PDF:Tool Bar Dock.pdf" to "Annual data-1.pdf""

How can I get my file renamed? I have to generate five .pdfs per record and each one is attached to separate auto email from FileMaker and for this exact file names are essential. Here is my script:

set theKnownPath to "PDF:Tool Bar Dock.pdf"

(--this is FileMaker's usual generic file name)

tell application "FileMaker Developer" to set the newName to cell "Extract-1 Applescript Name" of current record

tell application "Finder" to set the name of file theKnownPath to newName & ".pdf"

Thanks for any help

Oz

Well, it seems to be kind of a sneaky workaround. When you are printing to a file, the print driver takes the title of the frontmost window and appends ".ps" or ".pdf" to it. It just so happens that when Filemaker is the active application, and you are displaying the Filemaker toolbar (the one at the top of the screen) it will be the frontmost window, and its title (although you can't see it) is "ToolBarDoc." So the default title will be "ToolBarDoc.ps" etc., unless the toolbar is hidden, in which case the frontmost window will be your active database file (example, "MyDbase.fp5"). In this case the default file will be your database file name with ".pdf" or ".ps" appended to it. So, for your script to work, you would need to make sure that the tool bar is visible before running. There is no way to force it on in a script, but you can force it off. So, you could possibly try something like forcing the toolbar off with the "Allow ToolBars [off]" script step before you perform the applescript, and replace the first step of your applescript with:

set theKnownPath to "PDF:MyDatabaseName.fp5.pdf"

where MyDatabaseName.fp5 is the actual name of your database file.

  • Author

I tried this, but it did not work for renaming the file. I still get the message, using Script Editor 1.8.3 in OS9.2.2:

It doesn't look like you're telling the Finder the full path name of the file. Try using something like "Macintosh HD:PDF:In:Annual PQ.ps" or whatever the full path is.

  • Author

Tried changing the path to MacHD:Desktop Folder:PDF, etc. but that doesn't work either.

Would it be possible to rename just the bit before the .ps (or .pdf)? Would it make any difference?

Thanks for your help

I'm guessing that what is happening is an incompatibility between object types. It could be that the Finder doesn't recognize theKnownPath to be a file, though it should be obvious. You could try:

tell application "Finder" to set (name of file theKnownPath) to (newName & ".pdf") as text

The best way to debug it is to do this in the applescript editor, and make sure that the file you want to rename actually exists in the specified directory. In other words, eliminate as many variables as possible. Then start trying lots of variations on the syntax. It is Applescript after all.

smile.gif

  • Author

Coincidentally someone else wrote a solution for someone else on another list, and this works:

Set commonFolderPath to "Folder1:Folder2:"

Copy cell "FullName" of current record to fullname

Copy cell "SKU" of current record to SKU

Copy SKU & ".jpg" to SKU

Set FullPath to commonFolderPath & FullName

Tell application "Finder"

Set name of file FullPath to SKU

End tell

Thanks for everyone who tried to help me with my problem.

Kind regards

Oz

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.