Jump to content
Server Maintenance This Week. ×

Exporting container fields


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

Recommended Posts

  • Newbies

I am trying to write a script that incorporates a calculated Applescript to allow a user to select or create a folder, and then export the contents of a container field for all records in the selected set.

The AppleScript gets the path, and sets a field to its value. Such as: "/Users/username/Desktop/Pictures/"

For those who care, the AppleScript looks like this (it is in a calculated field so that I can retrieve the current database name--"MyDatabase" is an example of the calculated name):

set selected_path to choose folder with prompt "Please select a destination folder:"

set selected_path_posix to POSIX path of selected_path

set selected_folder to selected_path_posix as text

try

tell application "Filemaker Pro Advanced"

tell database "My Database"

set contents of field "Image Export Folder" to selected_folder

end tell

end tell

end try

I am not an AppleScript programmer, so this may be ugly, but it works!

Then I run a loop that

1) sets a variable $filePath to the path that was put in the field by the AppleScript, and appends the current field contents name, which results in (for example): $filePath = "file:/Users/username/Desktop/Pictures/image1.tiff"

2) Performs an Export Field Contents for the target field to the Specified Output File based on the path and name for the $filePath variable

There is some problem with the Specify output file path that is causing an error. I get a dialog that says the file cannot be created. It reads:

“image1.tiff” could not be created on this disk. Use a different name, make more room on the disk, unlock it or use a different disk.

What am I doing wrong in specifying the filepath? I've tried appending the word "file:" to the head (as above), leaving it out, and even adding the system "Filemac:/Users....etc."

If I uncheck Specify filepath, it or course works fine, but I need to automate the save since I am exporting hundreds of images.

It only needs to work in a Mac environment, so I am not too concerned with detecting Windows at this point...

Any ideas out there!?

Link to comment
Share on other sites

$filePath = "file:/Users/username/Desktop/Pictures/image1.tiff"

An absolute path to a folder should look like:

filemac:/volumeName/folder/folder

In your example it would probably be:

filemac:/Macintosh HD/Users/username/Desktop/Pictures/image1.tiff

See:

http://www.filemaker.com/11help/html/create_db.8.32.html#1030283

Link to comment
Share on other sites

  • Newbies

An absolute path to a folder should look like:

filemac:/volumeName/folder/folder

In your example it would probably be:

filemac:/Macintosh HD/Users/username/Desktop/Pictures/image1.tiff

See:

http://www.filemaker.com/11help/html/create_db.8.32.html#1030283

Hmmm....I tweaked my script to generate the absolute path properly, and got the same error. Here is the path my script is generating:

filemac:/Macintosh HD/Users/username/Desktop/test_export/image.jpg

Here is the formula that sets the variable $filepath:

=========================================

Let (

prfx = Case ( Abs ( Get (SystemPlatform)) = 1; "filemac:"; "filewin:");

prfx & Replace(Get(SystemDrive);Length (Get(SystemDrive));1;"") & Shot Breakdown::Image Export Folder & Shot Breakdown::Shot Image Info

)

=========================================

FYI - I delete the slash at the end of the detected SystemDrive with the Replace function because it gets doubled with the "Image Export Folder" path field, but it all seems to work to generate a proper absolute path as per your note.

This is very frustrating!

Link to comment
Share on other sites

  • Newbies

Hmmm....I tweaked my script to generate the absolute path properly, and got the same error. Here is the path my script is generating:

filemac:/Macintosh HD/Users/username/Desktop/test_export/image.jpg

Here is the formula that sets the variable $filepath:

=========================================

Let (

prfx = Case ( Abs ( Get (SystemPlatform)) = 1; "filemac:"; "filewin:");

prfx & Replace(Get(SystemDrive);Length (Get(SystemDrive));1;"") & Shot Breakdown::Image Export Folder & Shot Breakdown::Shot Image Info

)

=========================================

FYI - I delete the slash at the end of the detected SystemDrive with the Replace function because it gets doubled with the "Image Export Folder" path field, but it all seems to work to generate a proper absolute path as per your note.

This is very frustrating!

Figured it out!! In the found set some of the fields were empty, and therefore the script was unable to write the image so it generated an error. A simple IF test solved it:

If [shot Breakdown::Shot Image Info ≠ ""]

Export Field Contents (etc.)

End If

Works like a charm!

The functionality to let a user select and create a destination folder from within Filemaker seems like something that should be built in! It was fun figuring it out though--thanks for your help!

Link to comment
Share on other sites

This topic is 4805 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.