Jump to content

Applescript an import of a reference


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

Recommended Posts

I know, I know, I should bite the bullet and buy the TROI plugin. But I don't WANT to buy a plugin! I know it was mentioned elsewhere in the forum, that it is possible to set a container field to a picture, but to store it as a reference, in applescript. How?

Link to comment
Share on other sites

The Applescript code is basically:


set picFile to reference to file "Macintosh HD:MyFolder:MyFile.jpg"

set cell "picture" of current record to reference to picFile


Here is a simple script to import references to all jpg's from a folder into individual records of a Filemaker file:


tell app "finder"

-- change the following to suit your own folder name

set myfolder to "Macintosh HD:photos:jan2002"

set mypics to ( name of every item in folder myfolder) as list

end tell

-- change the following line to suit your database name

tell database "PicCatalog.fp5" of app "Filemaker Pro"

repeat with i from 1 to count of mypics

set filename to (myfolder &":"&(item i of mypics))

-- skip files that are the wrong type

-- change the following line to suit your image file type

if filename ends with ".jpg"

set picFile to reference to file filename

create new record

-- picture is the container field where the import goes

set cell "picture" of last record to reference to picFile

-- picref is a text field that holds the path/file name

set cell "picref" of last record to filename

end if

end repeat

end tell


If you already have graphics in your database and want to find the pathname that's stored you can do this:


-- Finding the filepath name of a picture in the current record only

-- If you want to do all records, place this in a Scriptmaker loop

tell database "PicCatalog.fp5" of app "Filemaker Pro"

-- "picture" is the name of the container field

set pathref to cell "picture" of current record

-- picref is a text field where the file name and path will be deposited

set cell "picref" of current record to pathref as text

end tell


Because of black magic involved in Applescript parsing, it won't work if you combine the two set commands from the above script into the following single line:

set cell "picref" of current record to (cell "picture" of current record) as text

I discovered this after a couple of hours of hair-pulling. Grrrr!

Link to comment
Share on other sites

Ok, well, I made the script I was making, it worked perfectly. Now, I'm making a nearly identical script that imports eps's in a loop, names match the primary key of the files I'm importing them into. The eps's are good, I can import them manually, but when I run the script I get an error: -43. Have you experienced this?

Link to comment
Share on other sites

Error -43 is "File not found," which generally means that you somehow specified the wrong file name or wrong path. Try putting a display dialog step in your script to see what file name and path applescript is getting. Like this:

display dialog myFilename & " " & myFilePath

Link to comment
Share on other sites

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