Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

  • Newbies
Posted

Hi There,

Does anyone know if it is possible to return an automated filename and filepath for the file selected in a container? It currently has to be entered manually - which can be laborious?

It would also be helpful to be able to select the creation and modification date (guess this is asking the impossible) but it would make life really easy if I know how.

Your help is very much appreciated as I am fairly new to FM and programming.

Posted

If the file inserted as a reference or stored?

Have you looked at GetAsText( containerfield )?

Regarding the create and mod dates, are these of the inserted image? A third-party plugin may be required to get the metadata from the image file.

  • Newbies
Posted

Hi Vaughan,

The file has been inserted as I plan to track documents within the database. They are not pictures but doc, xls and pdf files, for which much information normally exists.

I haven't quite figured out how to get to the stage of inserting "GetAsText( containerfield )" - whether it is in specify field or conditional formatting.

Thanks for the prompt response.

Posted (edited)

There was a discussion on the FileMaker (Inc.) forum, about something like this. Actually, they were asking how to set the "default folder" for an Insert dialog. I suggested using AppleScript to choose the file, as it has this option for its "choose file" dialog.

Of course, this is Mac only. But it is on every Mac.

--------------------------------------

set defaultFolder to path to pictures folder

set theFile to (choose file default location defaultFolder without invisibles)

--------------------------------------

Since you have chosen the file in the AppleScript, you have its path, and you could ask for whatever you wanted to know about the file (as a file). You also have access to a couple of built-in graphics tools ("Image Events" or `sips`), as well as to any metadata that Spotlight can see, via the mdls (metadata list) command. You would first set the data into AppleScript variables, then set FileMaker field to the values.

Try these commands in AppleScript Editor (was Script Editor).

---------------------

-- AppleScript info

get info for (choose file)

---------------------

-- sips example

set img to quoted form of POSIX path of (choose file)

set imgAll to do shell script "sips -g all " & img

----------------------

-- mdls example

set file_alias to choose file with prompt "Get the metadata of a file:" without invisibles

set unix_file to quoted form of POSIX path of file_alias -- convert to safe Unix path

do shell script "mdls " & unix_file

-- all metadata for chosen file

---------------------------

You would still need to coerce the AppleScript path to a FileMaker syntax path,* pass it to a FileMaker field. Then call a FileMaker script to Insert the file (AppleScript can insert a picture, but not a file).

do script FileMaker script "Insert the file script"

Yes, a little bit of trouble. But very powerful, reliable, and free.

* "filemac:/" & Substitute (AS path as text; ":"; "/" )

Edited by Guest
  • Newbies
Posted

Hi Fenton,

This is great advice and thanks for the response. I will attempt to try and work this out but I am now sure I need to use apple script in order to achieve what I want.

I still need to figure out where to add the applescript as I am new to FM.

Much appreciated.

Posted (edited)

There is a Perform AppleScript script step. You can enter the AppleScript as "Native" or "Calculated"; each with pros and cons. If it is Native, then you need to pass it any values needed.

It would be better really to get all the information from the "file" BEFORE it is inserted. you can use AppleScript to choose the file, get all the data needed, set the FileMaker fields to it, then call a FileMaker script to actually "Insert, [ ] as reference not checked".

If the files are already embedded, then you'd need to export each as a file somewhere, then get its info. You would need to preserve the name, using GetAsText (container), to use in the Export Field Contents step. The path could be the "temporary folder", which you can get via the FileMaker function, Get (TemporaryPath). That way they'll all be deleted automatically when you Restart.

It would be a bit of a process. But no part of it is really "complex" (eye of the beholder, etc.). You'd need to decide what info you wanted to get, in order to decide what tool (within AppleScript to use).

BTW, when you get "metadata" via AppleScript, you can ask for each piece by name (in many cases). You don't always have to use text parsing to get it. But things like size, date created, modified, etc., can be gotten in simpler ways, just using "info for" or "properties of" (similar).

[ P.S. Actually you will want to do a little Unix parsing on the particular metadata tag returned, to remove the 1st line (label), or remove extra spaces, etc.. It depends on how it's returned. You could also do this in FileMaker, but Unix has good tools (if you know them, and I sure don't 'em all :-). Here's a fuller example of what you can get with AppleScript & metadata.]

-------------------------------------------

(*

This is the general metadata you can get from a file.

Remove --comments (2 dashes) to run do a shell script line; comment out others ; only run 1 shell script to see its results

*)

-- Choose a file; or specify your own safe Unix path to a file, instead of these 2 lines.

set file_alias to choose file with prompt "Get the metadata of a file:" without invisibles

-- Coerce the Mac path returned to a safe Unix path

set unix_file to quoted form of POSIX path of file_alias

do shell script "mdls " & unix_file

-- all metadata for chosen file

-- you can also get a named element

-- do shell script "/usr/bin/mdls -name kMDItemContentType " & unix_file

-- but you need to cut it out

-- do shell script "/usr/bin/mdls -name kMDItemContentType " & unix_file & " | tail -1 | cut -d = -f 2 | cut -c 2-"

-- do shell script "/usr/bin/mdls -name kMDItemWhereFroms " & unix_file & " | tail -n +2 | cut -d = -f 2 | cut -c 2-"

-- download URLs, can be several several lines

--do shell script "/usr/bin/mdls -name kMDItemVersion " & unix_file & " | cut -d = -f 2 | cut -c 2-"

-- do shell script "/usr/bin/mdls -name kMDItemNumberOfPages " & unix_file & " | cut -d = -f 2 | cut -c 2-"

-- return # of pages, only works on some types of documents, such as PDFs

Edited by Guest
Posted

Wow excellent example. Here is a further mod of your script that calls choose file only once and returns all the results as text, also placing the results on the clipboard.

-- AppleScript info

set F to (choose file)

get info for F

set R1 to "INFO METHOD" & return & to_String(result) & return & return

---------------------

-- sips example

set img to quoted form of POSIX path of F

set imgAll to do shell script "sips -g all " & img

set R2 to "SIPS METHOD" & return & to_String(result) & return & return

----------------------

-- mdls example

--set file_alias to choose file with prompt "Get the metadata of a file:" without invisibles

set unix_file to quoted form of POSIX path of F -- convert to safe Unix path

do shell script "mdls " & unix_file

-- all metadata for chosen file

set R3 to "MDLS METHOD" & return & to_String(result)

set theResult to R1 & R2 & R3

set the clipboard to theResult

on to_String(the_record)

try

the_record as string

on error the_record

set astid to AppleScript's text item delimiters

set AppleScript's text item delimiters to "{"

set the_record to "{" & text from text item 2 to -1 of the_record

set AppleScript's text item delimiters to "}"

set the_record to text 1 thru text item -2 of the_record & "}"

set AppleScript's text item delimiters to astid

end try

return the_record

end to_String

Posted

Note that I recognize you would probably NOT use the above example as written if you were really trying to get info into FileMaker. You'd make a choice. But it is a good way to show the results of the three methods presented by Fenton, and help you figure out which one you might want to use.

Posted

Here's a bit more about getting the data into AppleScript variables, then setting them into FileMaker fields. These examples are the simple stuff the "Finder" can get from the file directly, or from its info. The Unix stuff would be much the same, but you'd need a separate: do shell script "unix_command unix_path" for each variable (since you can't set an AppleScript variable from within a Unix shell script (easily; please do tell if you know a better technique).

There's also (at the end) a subroutine to coerce an AppleScript "date" (timestamp) to a FileMaker syntax Timestamp. They are very similar.

A Unix timestamp is not really similar. So you'd need another if you get dates from Unix commands. You may not really need to.

---------------------------------

set F to choose file

-- some things, such as "default application" are only available via the "info", not directly; so we'll get it once

set file_info to info for F

tell application "Finder"

(*

-- you could set variables one per line (makes it kind of long)

set file_size to size of F

set creation_date to creation date of F

set mod_date to modification date of F

set file_kind to kind of F

set default_app to default application of file_info

*)

-- or set the variables as a list to the info as a list (the 2 lists must be the same length)

set {file_size, creation_date, mod_date, file_kind, default_app} to {size of F, creation date of F, modification date of F, kind of F, default application of file_info}

end tell

-- An AppleScript "date" is really a timestamp. It can be coerced to a FileMaker syntax Timestamp by calling a subroutine

set TS_file_created to my AS_to_FM_TS(creation_date)

set TS_file_mod to my AS_to_FM_TS(mod_date)

(*

-- the variables could then be set into FileMaker fields of the current record; they must be on the current layout for this simple syntax

tell application "FileMaker Pro Advanced"

tell current record

set cell "FileSize" to file_size

set cell "TS_file_created" to TS_file_created

-- etc.

end tell

save record

end tell

*)

-- subroutine to coerce an AppleScript "date" to a FileMaker Timestamp

on AS_to_FM_TS(AS_date)

set yr to year of AS_date

set Mn to month of AS_date as number

set Dy to day of AS_date

set dateTxt to (Mn & "/" & Dy & "/" & yr) as string

set timeTxt to time string of AS_date

dateTxt & " " & timeTxt

end AS_to_FM_TS

Posted (edited)

Example result from above script. Tried to paste into this response but it gets cut off.

(Clarification: from my "above" script, not Fenton's )

photo_script_result.txt

Edited by Guest
Posted (edited)

now do the PC side!

:

Actually, are there any plugins that allow applescript on the PC flavor of FM?

Edited by Guest
  • Newbies
Posted

Thanks for trying that Bruce, this problem seems like it is not easy to solve, but there are a few ways to get around it. I have also spoken to further developers here in the UK and they state that it is a difficult scripting problem. I think the solution Fenton has given maybe the closest to solving this one.

I am going to try and select the file first into the container by reference only. I can then script the filename and filepath to get the targeted meta information from the destination directory and filename, as this is now available from the container field. I realised you cannot open a stored file from container field, but it has to be exported first, hence, may be just as easy to point a reference only which will provide a filename and filepath for the subject in question.

Thanks for all your help to everyone here - truly talented bunch you are!

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