Jump to content

Applescript and set comment of file


aersloat
 Share

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

Recommended Posts

  • Newbies

Back in fm 4 and 5 (developer) 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 use the solution to log the photos and print out photo reports. The only real information entered about each photo in the solution was a location field and a description field.

I had another applescript which exported the contents of a calc field "infoComment" which was just location + description to the comment part of the original photo file. So, the real data from this photo logging solution is actually preserved in the file itself and can be parsed back out if the need arises.

In the move to OSX (years ago) the export feature ceased to work. Moving through FM6 we got much better importing and my import script was essentially replaced. So, now that we are at FM 7, 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 FM 7 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 the error message I get is basically "Finder got an error: Can't set comment of file "file://{long path to file -- seems fine}" to "location description".  Adding "as string" or "as text" to the back of the [color:"red"]set infoComment to cell "Comments" line or the [color:"red"]set comment of file... line doesn't seem to make a difference.



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. FM7 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 will try to enclose the screenshot of the error dialog from script editor.

Version: v7.x

Platform: Mac OS X Panther

dialog.jpg

Link to comment
Share on other sites

  • Newbies

Okay, I got some help over at MacScripter. Finder evidently can't handle the unix-like path generated by Filemaker on image import. So, I created a new calculation field called "LegacyPath" which puts the path into a format understood by finder. Another reply on MacScripter suggested changing some syntax around as well.

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




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 Pro"

	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 "LegacyPath"

			set file_comment to cellValue of cell "Comments"

			Set_Comment(file_path, file_comment) of me

		end tell

	end repeat

end tell

The export comments now works as expected.

FileMaker Version: 7

Platform: Mac OS X Panther

Link to comment
Share on other sites

This topic is 6500 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
 Share

×
×
  • Create New...

Important Information

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