Jump to content

Set Variable of Filepath:Filename


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

Recommended Posts

hey,

I am a newbie on applescript and I need some help.

I need an applescript to be able to grab the filename and its related path from a folder and place it in a filemaker variable script step. also the applescript or fm script will need to be able to run if there are more than one file in that folder.

help please?

thanks

Link to comment
Share on other sites

This can be done, but not exactly as you say. You need to provide a few more details about what you want to do.

It is a little (but not very) tricky to work with AppleScript and FileMaker Script Variables; which are kind of new. The FileMaker API does not expose those to AppleScript. So to set a script variable from AppleScript you would have to set a FileMaker field (global) to the AppleScript value (variable), then a FileMaker script could either set it into a variable, or more likely just use the global field).

As far as grabbing a file path via AppleScript via a dialog, there is a simple command:

choose file

This returns an "alias", which is very useful in AppleScript, but not to FileMaker.

If you want the result as text, which FileMaker can use, you'd use:

choose file as text

Both return a Mac syntax path, as opposed to a Unix syntax path. Neither of which is a FileMaker syntax file path; which is more like a Mac path, in that it includes the drive name, but like a Unix path, in that it is separated by "/" no ":". A little confusing, yes, but easy enough to convert. Here is an example of converting a Mac path to a FileMaker syntax path within AppleScript:


set mac_path to (choose file) as text



set FM_path to "filemac:/" & my ConvertPath(mac_path)



on ConvertPath(mac_path)

	set AppleScript's text item delimiters to ":"

	set x to mac_path's text items

	set AppleScript's text item delimiters to "/"

	set z to x's text items as text

	set AppleScript's text item delimiters to ""

	return z

end ConvertPath

Link to comment
Share on other sites

some more details.

I am dropping record files in a folder, the name of the files are unique. (Primary ids of the database) I need some way to grab that filename and incorporate it in filemaker scripts.(whether it be Variable steps or Global fields) In which I can handle the files(importing) the way I want it.

The applescript will be performed in a filemaker script. The folder itself it located locally. I need the filename of the file because the filemaker scripts will either import the record (if that ID is non-existent) or update the record.(based on the ID).

I can develop complex fm scripts to make the transition 'pretty'. I need to be able to grab the record into filemaker.

too add things a bit more tricky, at times, there can be more than one file in that specific folder. fm/applescripts will need to be able to realize that multiple files need to be processed.

does this help?

thanks

RB

Link to comment
Share on other sites

I need the filename of the file because the filemaker scripts will either import the record (if that ID is non-existent) or update the record.(based on the ID).

It is hard to talk about complex operations if terms are ambiguous. A file is a file and a record is a record. "Import the record" is very ambiguous since you're referring to an external file. You could mean:

1. Create a new FileMaker record and put this file into a container field as a file.

2. Create a new FileMaker record and put this file into a container field as a picture.

3. Import (or read/set) the text contents of the file into a field (or fields) in the record.

4. Import the csv or tab-separated data of the file into multiple records.

5. ?

Since you also say "update the record" if the ID exists, there are more questions, like "update what?". You can only update Fields in a Record; so those must be specified.

It is all doable, and I've likely done it, but no one knows what exactly you want to do.

Link to comment
Share on other sites

I apologize for being difficult

the file will create new Filemaker record or update the fields in a record.

the file name will dictate whether the fm script will import to create a new record or update the fields.

let me know if i am being more difficult

Link to comment
Share on other sites

Well, you need to be more descriptive, more details. Yes, it can be done, that is not really problem. Yes, you can match the name of the file (actually only part of the file name, as the complete file name includes the extension; i.e., "C112.txt" is a file name; but you just want to compare to "C112"; there are AppleScript routines to do so). You can then do a Find, in AppleScript, for that record in FileMaker.

Alternatively, you can create the file name, ( ID & ".txt") within FileMaker, and use the • Matching records option of the Import script step to Import the text files into an table dedicated to that, then deal with the contents. It sort of depends on whether it's easier to parse the data with FileMaker or with AppleScript, which sort of depends on your skill with either.

Or maybe you're just going to update the records using Import Matching directly from the file, because it is a precise comma-separated or tab-separated (or Excel) file of all the FileMaker record's fields. I have no way of knowing any of these details from your description.

Link to comment
Share on other sites

  • 2 months later...
  • Newbies

Hello, I'm looking for similar assistance with Passing Applescript results to a Filemaker script.

I have an Applescript that asks a user for a HiRes Image and makes a thumbnail with padding and copies the Thumbnail and the HiRes to specified folders. What I'm missing is how to pass this image name to FM and have the thumbnail inserted into the "Picture" filed.

Here is the FM section:

set mac_path to (LoRes_Path) as text

set FM_path to "filemac:/" & my ConvertPath(mac_path)

set FM_fullpath to FM_path & "/" & new_image

on ConvertPath(mac_path)

set AppleScript's text item delimiters to ":"

set x to mac_path's text items

set AppleScript's text item delimiters to "/"

set z to x's text items as text

set AppleScript's text item delimiters to ""

return z

end ConvertPath

tell application "FileMaker Pro Advanced"

tell database "Inventory.fp7"

tell current record

set cell "Picture" to file FM_fullpath

end tell

end tell

end tell

Here are the error results:

tell application "FileMaker Pro Advanced"

set cell "Picture" of current record of database "Inventory.fp7" to file "filemac:/Macintosh HD/Users/Shared/DatabaseImages/LoRes/Macintosh HD:Users:Shared:DatabaseImages:LoRes" of current record of database "Inventory.fp7"

--> error "Object or property is the wrong type." number -10001

any help would be appreciated.

Ben

Link to comment
Share on other sites

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