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

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

Recommended Posts

Posted

I have a script that opens the "Insert File" window. I'd like to add the folder the file can be found in. "Specify source file" doesn't work, because I need a designate a file there. So what I want to be able to do is to specify the source folder. Does anyone know how to do that?

Thank you!!

Posted

Are you trying to Insert a specific known file? If so, there's no need to even look at the folder; you can just specify the file path (in FileMaker syntax), by putting it into a script Variable, then Insert it using the variable.

Or, do you want to "choose an arbitrary file from a specific folder"? If so, is this always on a Mac? If so, you could use AppleScript to choose the file, as AppleScript has an optional "default location" parameter of its "choose file" command; which produces your standard OS choose file dialog, with that folder as the starting point.

A cross platform method, if you have access to the folder, would be to put a very small file in the folder. In a script, Insert that file, without dialog, into a global container field. Then issue a 2nd Insert command. It will open at the last folder used.

Posted

Thank you, Fenton!

I indeed want to choose an arbitrary file from a specific folder. I've never used AppleScript before, but will give it a try. They other option you mentioned is very clever. I might just go for that one.

Thanks again,

Ente

Posted

Just for fun. Here is a FileMaker file with several scripts, using variations of the "choose file" AppleScript command, returning either an AppleScript path, a Unix path, or a FileMaker syntax path (derived from the Unix path).

You can view the possibilities of choose file, by launching Script Editor (in Applications/Applescript), then showing the Library window (which has the "dictionaries" of various applications, etc.). It will be under Standard Additions, then in the User Interactions section. Heck, I'll just paste it here; it's short (items in brackets are optional):)

choose file v : Choose a file on a disk or server

choose file

[with prompt string] :( the prompt to be displayed in the dialog box

[of type list of string] :( a list of file types or type identifiers. Only files of the specified types will be selectable.

[default location alias] : the default file location

[invisibles boolean] : Show invisible files and folders? (default is true)

[multiple selections allowed boolean] : Allow multiple items to be selected? (default is false)

[showing package contents boolean] : Show the contents of packages? (Packages will be treated as folders. Default is false.)

→ alias : the chosen file

Posted

I'm sorry, but I really don't understand it, while you did so much to make it clear! Sorry! (I don't even know how to "set myFile to (choose file without invisibles)". I'll try to learn, but it seems hard.

Posted

By the way, the option without appscript didn't work, because when you have FM select a file automatically, it doesn't "remember" the location.

Posted

I thought it did remember the last folder you Inserted from. It seems to for me.

I modified the FileMaker example using AppleScript, to be more intelligent about remote paths. Otherwise they wouldn't work, because Unix returns "Volumes" as the start of the path for remote files. Yes, you could also just remove that with a calculation in FileMaker, perhaps more easily. But since I'm using AppleScript, I might as well remove it in AppleScript.

You don't really have to know much AppleScript to use these. There is nothing specific to my machine or file really, except the name of the FileMaker field, which is just "Filepath".

Actually, here's another simpler mechanism for converting a Mac path to a FileMaker path. I was previously converting a Unix path, because at first glance it appears more similar. But really it's easier to just Find/Replace the ":" with "/" in a Mac path.

(It is a good example of how AppleScript does "find & replace".)

Posted

It seems to only remember it when you insert it yourself, using the window, not when you use automatic insertion.

So, you say I don't need to understand applescript, but then how do I tell it which path to use?

Posted

wow, I really, really appreciate you not giving up on me, but maybe you should. I still don't understand. The only thing I understand is that there are 6 scripts, each one more complicated, using AppleScript. And I can see the result of them, but I have no clue how to transform them to do what I want (tell filemaker where the files are I want to choose from to insert).

Posted

A FileMaker Perform AppleScript step runs the AppleScript. That AppleScript is handling the "choose file dialog," then it is converting the path returned into a FileMaker syntax path. The paths are very similar, but not the same. It is then setting that FileMaker syntax path into a FileMaker text file. At that point the AppleScript is done.

The FileMaker script continues, setting the text of the global field into a script Variable. Then an Insert File step is using that script Variable as the file's path to insert. The Insert step, for some reason, cannot read a value directly from a FileMaker field, hence the Variable is needed.

If you find the latter part of the AppleScript confusing. You could just set the AppleScript path, after converting to text, into the FileMaker field. Then use a FileMaker calculation to substitute "/" for ":" and prefix it with "filemac:/"

Posted

Thank you!!! I'll study it when my head is clear again. I don't think I can process anything anymore... Thank you again for spending so much time and effort on my question!

Posted (edited)

OK, here is the same thing with only one script using AppleScript, and only a few lines of AppleScript, just to get a file path. The calculation to convert the path to FileMaker syntax is in FileMaker.

But you'd still need to edit the AppleScript to use a different default folder. I used "path to Documents folder," because everyone has it, and AppleScript knows its path. If you want to see what a path looks like you can run this simple AppleScript, in Script Editor:

choose folder

It will return something like:

alias "Macintosh HD:Users:fej:Documents:Scripts:"

or

alias "Macintosh HD:Users:Shared:"

That is what the "default location" parameter in the choose file command wants, a full Mac alias path. Notice that the 1st path above has MY short user name in it. Hence those kind of paths can only be used directly by one person; not to mention that people can rename their hard drives. If you use something like "path to documents folder", then you could add a path that might work for other people. Or if you stick to common folders which do not have the user name in them, like the Shared folder.

Which, BTW, has its own shortcut,

path to "sdat"

Insert_File_wDefault_Folder_AS_simple.fp7.zip

Edited by Guest
Posted

I think I didn't make it clear enough what i want to do. I don't want to get the path, I want to put the path into the script, so that when I run the script and insert a file, the window opens in the folder I want it to.

Posted (edited)

First, the "default location" is a parameter of the choose file (or choose folder) command; which produce a dialog. The "default location" just specifies where that dialog first opens. The idea being that you would want to choose a file of that folder, or within its contents.

set start_folder to (path to desktop)

choose file default location start_folder without invisibles

Opens the file navigation dialog at the desktop. I already uploaded a file which lets you specify the default folder, choose a file, and Insert into FileMaker. I don't know what else you'd want.

Of course you are going to have to modify the step of the AppleScript which specifies the default folder. No one else knows or likely has your folder, unless it can be specified in reference to a known folder (Documents, Desktop, etc.). That is why I built the dialog with 2 steps. So that you can more easily modify what that starting folder is. "start_folder" above is just an AppleScript variable. These are declared on the fly, with whatever name you want (within reason). So you can name the variable whatever; just be sure to use it again in the choose file step.

If you want to actually open a folder in the Finder, that is something else, though similar. But I don't see why you'd want to do that if your objective is to choose a file to Insert in FileMaker.

Edited by Guest
  • 11 months later...
Posted

Hi Fenton,

Has there been any change in AS between Leopard and Snow Leopard.

I installed Snow Leopard over the weekend, and when I used a file I had a couple of these scripts in, it put me into a loop.

They used to work great in v9 and v10, but now I'm having problems and want to either confirm or eliminate these as a possibility.

TIA

Lee

Posted (edited)

Yes, AppleScript did change with Snow Leopard.

The 'open file' command was affected.

http://filemaker.custhelp.com/cgi-bin/filemaker.cfg/php/enduser/std_adp.php?p_faqid=7354

http://forum-en.filemaker.com/fm/board/message?board.id=FM-en-4&message.id=25338

Edited by Guest
Posted

There are also a few changes within AppleScript itself, partly to do with subroutines and access to the Scripting Additions (one of which is Standard Additions, which has several functions that are commonly used). It is all a little obscure to me, something to do with ownership for security reasons I think; but I've had no real problems.

Lee, if you could post more specifics, we might be able to pin down what went wrong. It is unclear whether the "loop" was within AppleScript (a "repeat"?) or a FileMaker Loop (which could have an AppleScript with "repeat" within it). Kind of hard to tell.

Posted

Hi Fenton,

I pulled this out of your file:

[color:blue]Insert File wDefault Folder AS simple.fp7

Posted in the Thread Link

File AS File: Insert TechFilePath from Documents folder

Set Error Capture [ On ]

Set Field [ ISO_SiteArticlesFilesVideos::TechFilepath; "" ]

Commit Records/Requests

[ No dialog ]

Perform AppleScript [ Native AppleScript: set myDocs to path to Documents folder

set Mac_path to (choose file with prompt "Choose a file to Insert into FileMaker" without invisibles default location myDocs) as

Unicode text

set field "TechFilepath" of current record to Mac_path ]

If [ ISO_SiteArticlesFilesVideos::TechFilepath ]

Perform Script [ “__Insert File from AS” ]

End If

TIA

Lee

Posted

Hi TheTominator,

My error, I should have cited the file posted by Fenton too.

Thanks for for posting the links, I appreciate it.

Lee

Posted

Thanks Fenton,

I'll check other things and see if I can find something else effecting this.

Lee

Posted

partly to do with subroutines and access

Oh yes - have you noticed this previously allowed recursion:

set end of myList to myList

...next thing you are brought to after severe crunching taking place is a "Would you like to inform Apple..." dialog!

--sd

Posted (edited)

No, didn't notice 'til now. But I don't really see why you'd use the above, as setting the end of a list is usually an (faster) alternative to setting a list to itself.


set List1 to {"one", "two"}

set List2 to {"three", "four"}



repeat with i in List2

	set end of List1 to i as text

end repeat

return List1



-- {"one", "two", "three", "four"}

But yeah, it shouldn't crash and burn.

Edited by Guest
Posted

But I don't really see why you'd use the above

Ah! This is obviously sidetrack perhaps even hijack of the thread.

The scenario is as follows, we recieve a long list of fields and values sometimes spanning over several records showing an invoice and it's itemlines utterly and completely flat.

It is pretty simple to pluck each field via position( and then a repeating calc'field. This is nice since a layout with a flat structure including repeaters have exactly the same format as a structured with a portal when dealt via applescript:

http://tokerud.typepad.com/filemaker/2006/06/new_record_with.html

The scraped data is put into a global textfield in a sample of records each picking their own set of record data.

Now the problem occures when only one record needs to get scraped then wouldn't item 1 point at the first record but instead the first field/cell when looping thru the found set ... by adding the entire list to itself can you be sure to pick item 1 correct as record and not field.

Now it ended not to be the solution I used, but relied instead on a hybrid a real duct-tape solution back and forth where I used filemakers assumption as to how many records was needed.

Another way would be calculate how many doublings of the found set Ln(x)/ln(2) and then generate the records ahead and then take the entire found set in the layout with the repeaters ... but I remember issues where I ran out of bufferspace and this scraping business is vital to the care of the customer portfolio and I didn't wish to take any chances here.

My guess is that you can see a 3rd solution here ... that I in grievance must recognize as being more clever than my approaches.

The real problem was to count the number of {{ inside a list and interpret them correctly, no matter how many records in the particular case of scraping.

--sd

Posted

Not quite sure what you mean by

Ah! This is obviously sidetrack perhaps even hijack of the thread.

Lee

  • 2 weeks later...
Posted

Update.

I installed the lastest patch to Snow Leopard, and now the script works again. I'm wondering if this has been the case with others?

Lee

Posted

Glad they've managed to nail your problem - mine prevails:


set myList to {"a","b"}

set end of myList to myList 

--sd

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