This morning I was playing with the idea of using AppleScript (using do shell script) to trigger the FMP URL and pass any desired parameter. This seems a little cleaner to me, though it does severely limit the platform possibilities.
Has anyone else been using this particular technique, and if so, do you have any comments to share about it, e.g. possible pitfalls, successful use cases?
I've demoed a similar approach through ActiveX on Windows about a decade ago, There used to be a demo file available for this, called something like "run script by redirection".
The issues mainly tend to be timing: whether or not you need or want to wait for the script to complete. There is a definite order in which FM puts scripts in the stacking order and scripts called by AppleScript and ActiveX tend to go fairly low in that order.
In that sense you need to carefully craft the hand-off between internal scripts and the scripts called from the outside.
I haven't checked out your new method via AppleScript ( I'm on Windows ) but I'm a bit confused by your comment of needing a webviewer on the layout. I've never had any trouble calling the fmp protocol via the Open URL script step. I threw together a quick example file, but alas, I can't seem to figure out how to upload it with my comment. It should be easy enough to test yourself, or I could upload the one I have if you could point me in the right direction.
Nevermind, I found it.
fmpurltests.fmp12.zip 63.2 K
I had completely overlooked the possibility of using Open URL script step to do this -- That seems like it would be much better for this sort of task.
Thank you for mentioning it. I'm going to check it out.
Many thanks and very best,
Addendum: Thanks for the sample file!
Addendum 2: If I could like your reply several times, I would. What you did is much better, and doesn't introduce any platform issues. Thank you again Ryan!
Thank you for the information Wim. I appreciate it. I have indeed been finding that AppleScript does seem to fall low in the stacking order. I don't see this as wrong -- just something which needs to be understood and dealt with, as you mentioned.
If you use MBS Plugin, you can use the functions
FM.RunScript, run a script now:
FM.RunScriptLater, run a script in a few seconds or minutes:
FM.RunScriptIdle, run a script when using is idle for some time:
For all you can pass filename, scriptname and parameter as text and you can calculate them.
I use the Open URL method very successfully. I have a field with a sequence of script names and a master dispatch script that traverses the list and uses Open URL to run whatever scripts I want in whatever order I need them to run.
My URL calculation looks like this.
"fmp://" & Get ( HostName ) & "/" & Get ( FileName ) & "?script=" & $script_name & "¶m=" & $script_param
Primary concern is of course context. Turns out because the Open URL is calling the local FMP client it works within the current clients context.
Thank you ch0c0halic.
This is very cool, and I look forward to swapping this into a project where I have gone down a needlessly complex path to accomplish the same result.
Thank you Christian.
BaseElements and ScriptMaster have some similar functionality which I have used in the past.
The plugins work really great. One advantage of the plug-in approach is that it allows for triggering the script from the context of the calculation engine, which is a very powerful ability.
Thanks for adding to the conversation.
Perform script by name, or by ID, is sorely missing. We could do a lot of things with it.
The open url doesn'tw work for me, for 3 reasons :
- Not server side compatible
- When I tested on the client, there was some flashing, or it openend a new window, I don't remember
- Parameters must be encoded, they're much more limited in size than rela parameters
So, I resorted to create a script to which I pass script_id, and filnemane, and in which I've lots of else if that branches to the correct script
So please plese plese FMI, create a real Perform script by Name / ID (same interface as layout with also file specification. This will open tremendous possibilities.