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

Trying to create a relative path folder with applescript


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

Recommended Posts

  • Newbies
Posted

Hi. I'm trying to integrate a type of CMS into my database. On a click of a button I want to create a folder from the relative path of the current database file. I'm pretty advanced in applescript so I'm not asking how to create a folder/file, but I can't seem to find a property or function for FileMaker to retrieve the current DB path. If I could get that I would be able to extract the relative path. Has anybody ever crossed this path?

Posted

There is a function in FileMaker now, Get (FilePath), which returns a FileMaker syntax path, ie.,

file:/hard drive/folder path/file name

Which you can convert to an AppleScript syntax path via a FileMaker calculation. You'd also want to strip off the file's name, so you'd have a Mac path to the file's folder:

Substitute ( Get (FilePath); ["file:/"; ""]; ["/"; ":"]; [Get (FileName) & ".fp7"; ""] )

But this is only going to work if the file is local. I'm not sure what it returns on a hosted file; but it would likely not be very useful, as you want a relative path to a local folder/file.

  • Newbies
Posted

Nice, thanks. That's good cause I can use that as the relative path as an AS variable. One thing I'm not sure if it's going to give me a prob, is that the FM DB is on an external drive. For some reason the FilePath var doesn't return the"/Volume/..." in front.

Also I'm not quite sure how to have FM return the value from the "Get (FilePath)" to AS. I looked all over Google but I have yet to find anybody who can send variable values to applescript.

Reading up on FM script, my guess is that i will have to use the Perform AppleScript [“”] function. I was hoping to do it the other way around from an AS view (...some AS..."some FM functions" ...more AS). Like how in AS there is "do shell script", I wish there was "do FM script"

Posted (edited)

Well, I generally prefer to run AppleScript via the FileMaker Perform AppleScript step, usually using the "native" option, especially for longer AppleScripts. It is often (much) faster than running an external AppleScript, perhaps because FileMaker has access to more RAM. (I have not compared since 10.6 however, where the release notes state that AppleScript has access to more RAM.)

To get a value from FileMaker into AppleScript, it is often just:

set aVariable to cell "some field" of current record

that is if you're on that record and the field is on the layout; you can use a dedicated layout for this if the field isn't on the layout, or specify it by layout or table (table occurrence)* name.

If you have not gotten it (and likely not, as FileMaker doesn't distribute it anymore with FileMaker, for some reason), you should read this. It will give you much help when trying to figure out what the actual objects/commands are. There's a chart.

http://fmdl.filemaker.com/MISC/fmp10/fp/apple_events_reference_wwe.zip

BTW, there is an AppleScript command almost identical to what you wished for:

do script FileMaker script "some script name"

Though there are also many ways to set data directly in FileMaker, as well as do Finds and access data.

As I said, I prefer to run AppleScripts via Perform AppleScript. Another advantage is that it allows you to use FileMaker to control the actions and timing (FileMaker will wait for the AppleScript's results, generally). A Set Error Capture ["On"] step, before the Perform AppleScript, followed by a Get (LastError) afterwards can capture AppleScript errors. Unless you use a Try block within the AppleScript, in which case it's up to you to tell FileMaker about it, if necessary.

You can set a global field in FileMaker; though that is also subject to much the same rules as setting other fields, ie., on the layout, or specified by layout or table (table occurrence) name. Unfortunately there is no way to set a script Variable in FileMaker from AppleScript. It is however possible to use a script variable to pass a script $variable value to AppleScript, if you use the (•) Calculated AppleScript option; or via a calculation field, if the variable is $$global.

*The reason I've said this twice is that although AppleScript uses the term "table", it means a FileMaker table occurrence name, on the Relationship Graph. No one sees the actual "tables" in FileMaker. And everyone mostly uses the term "table" instead of "table occurrence" in documentation (fear of relationships? inadequate text completion tools? :(-).

Edited by Guest
  • Newbies
Posted

Thanks. I was wondering where the apple events reference was since FileMaker's texts kept mentioning it. It's kind of buried in their site.

I'm getting a bit more accustomed to FileMaker's script steps. The editing interface feels a bit clumsy but I'm learning to deal with it. It was driving me nuts that I couldn't get applescript to compile correctly in a calculated step. But then I found somewhere that I needed the "¶" for end of lines and then everything locked into place. I figured the manuals would have made that importantly apparent.

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