Filemaker Pro problem

I saw a similar thread from last August; however, the suggested applescript doesn’t work for me so here it goes…

Back in Filemaker Pro 4 and 5 (developer) under 9.2 we had an applescript which imported refs to photos in a chosen folder and parsed out some information from the file names. Our users could then log the photos and print out photo reports and the like. The only real information entered about each photo in the database solution was a location field and a description field.

I had another applescript which exported the contents of a calculated field “infoComment” which was just location + description to the comment part of the original photo file. So, the essential data from the filemaker photo logging solution was actually preserved in the comment part of the photo file itself and could be parsed back out if the need arose.

In the move to OSX (years ago) the export feature ceased to work and for a variety of reasons I never got around to fixing it. Moving through FMPro6 we got much better importing support and my import script was essentially replaced. So, now that we are at FMPro7, and I have Developer sitting here, I am trying to clean up the solution and re-enable some of the features which have been missing the past few years. I can’t seem to get FMPro7 and Finder to play nice together to set the comment to my desired info.

my basic script is this:


tell application "FileMaker Pro"
      activate
        set recordsFound to every record
        repeat with i in recordsFound
           set pictureFileRef to cell "File Path" as string
                set infoComment to cell "Comments"
              tell application "Finder"
                       set comment of file pictureFileRef to infoComment
               end tell
        end repeat
end tell

When I run this from script editor I get an error.

Adding “as string” or “as text” to the back of the set infoComment to cell “Comments” line or the set comment of file pictureFileRef to infoComment line doesn’t seem to make a difference. The script fails with the same error running from both script editor and filemaker.

So, anybody have any ideas? A simple script of the form


tell application "Finder"
       set comment of (choose file with prompt "choose file") to "done"
end tell

works just fine from script editor. The text of the error message would indicate that FMPro7 and Finder seem to agree on the file path as well as the data to go into the comment field…

Any insight would be greatly appreciated. I have the feeling that I am missing something very simple.

I have never had much luck with coercion within a FileMaker tell block. Seems like anything that can be a string, including integers, comes out as a string. Speaking of tell blocks, I think you need either a “database”, “document” or “window” tell block in your script. My first guess would be “document” since you seem to be working with a found set of records. I also don’t think embedded Finder tell blocks work and play well within a FileMaker tell block. Try moving this out to a handler.

Those are my quick thoughts.  I’ll give some of this a try and post what I find.

OK, first of all you have a repeat loop but you aren’t referencing that record. This script works with FM 6.

to Set_Comment(file_path, file_comment)
	tell application "Finder"
		set comment of file file_path to file_comment
	end tell
end Set_Comment

tell application "FileMaker Developer"
	tell document "Applescirpt.fp5"
		set rec_count to count of every record
		repeat with rec_idx from 1 to rec_count
			tell record rec_idx
				set file_path to cellValue of cell "file path" --of current record
				set file_comment to cellValue of cell "comment" --of current record
				Set_Comment(file_path, file_comment) of me
			end tell
		end repeat
	end tell
end tell

When you set your variable to every record you are creating a list of lists. With a large found set of records, this could require quite a bit of memory. Just get the count and then step through the records by index.

Thanks Don

I gave that a go but got exactly the same error message. The old script worked to perfection under OS9. Thanks for the index advice. We never have more than 200 or so records really so it hasn’t been an issue. The document name changes for every document-- I hard coded the name in your sample script but it didn’t make a difference. Any other ideas?

What is the exact content of the field that holds the file path (if possible, please post actual data for one of the records)? Based on the error that you reported, the paths are in a form that Finder doesn’t understand. It needs paths such as:

Mac HD:Users:user:some folder:

– Rob

The exact content is what I have in my original message-- obviously I replaced the specific names with generic-- so the path is in a unix “/” html style format. That path is generated automatically on import from filemaker’s import command and is the path that filemaker uses to “reference” the file. These are all referenced files, by the way, and the path is hard coded so to speak. If you move the file filemaker can no longer display the photo in the container.

I thought that Applescript could reference / paths now. If not it looks like I have to create a calculation field in Filemaker that changes my unix path to a legacy mac “:” path. I will give that a go.

AppleScript can work with both types of paths but many (most?) applications cannot. Finder is one of the applications that cannot.

– Rob

Alright. Thanks guys. I created a new calculation field in filemaker called LegacyPath which turns the unix path into a finder friendly path.

Substitute ( Substitute ( File Path ; "file://" ; "") ; "/" ; ":")

The comment export now works. I am sure that one could do the conversion in AppleScript, but it was easy enough in filemaker.