Custom Function: FMP Safari integration via AppleScript + Javascript


I was over at the old forum today and noticed this post:

It is a question regarding how to have FMP execute some Javascript within a page in Safari.

I worked on this idea some a number of years ago. Since it involved a fair amount of scripting, I wrote a custom function to encapsulate all of the detail work.

I don't believe I shared the function publicly, however, because I didn't think there was much demand for it, and it is a pretty fragile work flow, given the change that can happen with web pages. Also, it involves the reduction of some security/access restrictions, and I did not want anyone to use it without understanding the implications.

Having just seen a question about this topic, however, I thought it might be worth sharing the custom function, and I will attach a sample file here. (123.4 KB)

Overview of Custom Function:

The gist of what the custom function does is that it allows you to specify some Javascript code, and a target URL, and then (if permissions allow) it will find the tab/window in Safari with the matching URL, and it will then execute the Javascript within the target tab/window.

Within the Javascript environment there are a few built-in functions that I wrote to try to streamline simple tasks, such as populating form values. There is also a callback feature that used to use the FMP URL protocol to push a message back to FMP. Though the calback feature still exists, Safari now (rightfully) challenges the invocation of the FMP URL. I have not investigated whether or not there is a preference that can be set to whitelist the FMP URL within Safari.

Here is a screenshot of the custom function definition:

And here is an example of a script using the function:

A few parameters are fed to the custom function, and it returns the necessary AppleScript...

As I indicated above:

This particular integration has the drawback of being somewhat fragile, so I encourage folks to always keep that in mind.

Thanks for reading, and kind regards,


@Cecile : Apologies if I selected the wrong channel for this post. This seemed like the best fit.


amazing stuff - @steve_ssh - thanks for sharing!

1 Like