FM.RunScript
------------

Runs a script in any open FileMaker file.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) | [1.2](newinversion12.md) | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes |

MBS( "FM.RunScript"; FileName; ScriptName { ; ScriptParameter; ScriptControl } ) 

**MBS**( **"FM.RunScript";** /\* Runs a script in any open FileMaker file. \*/  
**$FileName**; /\* The name of the FileMaker File that contains the script \*/   
**$ScriptName**; /\* The name of the script to run.  
Or the ID of the script in the current file. \*/   
**$ScriptParameter**; /\* Optional; The Parameter to Pass to the script. \*/   
**$ScriptControl**) /\* Optional; The script control mode.  
Can be Pause, Halt, Exit or Resume.  
Default is Pause.  
  
May be ignored by FileMaker.e.g. "pause" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| FileName | The name of the FileMaker File that contains the script |  |  |
| ScriptName | The name of the script to run.   Or the ID of the script in the current file. |  |  |
| ScriptParameter | The Parameter to Pass to the script. |  | Optional |
| ScriptControl | The script control mode.   Can be Pause, Halt, Exit or Resume.   Default is Pause.      May be ignored by FileMaker. | "pause" | Optional      Added in version **9.3**. |

### Description

Runs a script in any open FileMaker file.   
You can also pass a text string to the Script as a Parameter. The parameter can be retrieved by using Get(ScriptParameter) in the script that plug-in is calling. The basic concept behind triggering scripts with a plug-in is as follows. In order for the Plug-in to call a script it must be part of a calculation that is evaluated. For example to cause a script to run when a field is exited, you place the MBS function call in the auto-enter calculation of the field you want to serve as the trigger. When the field is exited the Auto-enter calculation is evaluated and the MBS function is fired off.. Placing the function call in the Field Validation calculation of the trigger field will cause the script to run on Record Exit. NOT on field Exit. This is because Validations by calculation happen at when the record is exited. Anywhere you have access to the calculation dialog you can place a Script trigger function. When the calculation is evaluated the script will run. This includes the new conditional formatting calculations that can be placed on many layout objects. While this opens up new opportunities, you might find that your script is being called continuously.  
  
see also [FM.RunScriptIdle](FMRunScriptIdle.md), [FM.RunScriptLater](FMRunScriptLater.md) and [Schedule](component_Schedule.md) functions.  
  
  
With plugin version 6.0 or newer the script name can be a script ID number. In that case the plugin queries the script name for the given script ID. This allows to call scripts by ID and avoid problems if scripts are later renamed.  
  
Notice: FileMaker 19.2 adds a fmplugin extended privileges. If you have such an extended privileges to allow the plugin to trigger scripts, you need to grant permissions for it. If such a privilege is not defined, the plugin is allowed to trigger scripts. See FileMaker product documentation for details.  
### Examples

Trigger a script

 Let(  
\[  
trigger = MBS ("FM.RunScript"; Get(FileName); "Triggered Script"; "")  
\];  
1  
)  
Trigger script by ID:

 MBS ( "FM.RunScript"; "test.fmp12"; "12" /\* PrintRecords \*/; "Hello World")  
Registers a hotkey option-control-command-c to run a script if the right file name is current:

 Set Variable \[ $Hotkey ; Value: MBS ("[HotKey.Register](HotKeyRegister.md)"; "C"; "option control command") \]  
Set Variable \[ $r ; Value: MBS ("[HotKey.SetEvaluate](HotKeySetEvaluate.md)"; $Hotkey ; "Let(\[ name = Get(FileName); r = if(name = \\"Hotkeys\\"; MBS ( \\"FM.RunScript\\"; \\"HotKeys\\"; \\"test\\"; \\"Hello World\\"); \\"Wrong file\\") \]; r)") \]  
### See also

- [FM.QueryCustomFunctionsList](FMQueryCustomFunctionsList.md)
- [FM.RunSaveAsXML](FMRunSaveAsXML.md)
- [FM.RunScriptIdle](FMRunScriptIdle.md)
- [FM.RunScriptLater](FMRunScriptLater.md)
- [FM.StopScriptIdle](FMStopScriptIdle.md)
- [HotKey.SetEvaluate](HotKeySetEvaluate.md)
- [Preview.CreateWithControl](PreviewCreateWithControl.md)
- [Schedule.EvaluateAfterDelay](ScheduleEvaluateAfterDelay.md)
- [SyntaxColoring.AddContextMenuCommand](SyntaxColoringAddContextMenuCommand.md)
- [TextView.CreateWithControl](TextViewCreateWithControl.md)

### Release notes

- **Version 9.3**
    - Added mode parameter to [FM.RunScript](http://www.mbsplugins.eu/FMRunScript.shtml) and [EventMonitor.SetCardWindow](http://www.mbsplugins.eu/EventMonitorSetCardWindow.shtml) functions.

### Example Databases

- [MongoDB/MongoDB Audit](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/MongoDB/MongoDB%20Audit.shtml#1ScriptAnchor_)
- [Schedules/OnRecordEdit Trigger](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Schedules/OnRecordEdit%20Trigger.shtml#1ScriptAnchor_)
- [Schedules/Schedules](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Schedules/Schedules.shtml#1GroupButton6.0000000123.000000031.0000000322.0000000LayoutObjectAnchor_)
- [ScriptTriggers/Trigger Script On Field Exit](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/ScriptTriggers/Trigger%20Script%20On%20Field%20Exit.shtml#1291FieldAnchor_)
- [ScriptTriggers/Trigger Script On Record Exit](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/ScriptTriggers/Trigger%20Script%20On%20Record%20Exit.shtml#1291FieldAnchor_)
- [Utility functions/RunScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Utility%20functions/RunScript.shtml#4ScriptAnchor_)
- [WebHook/Trigger script with Webhook/WebHook Listener](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/WebHook/Trigger%20script%20with%20Webhook/WebHook%20Listener.shtml#3ScriptAnchor_)
- [Win Only/Search Scripts](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Win%20Only/Search%20Scripts.shtml#1ScriptAnchor_)
- [Window/Schedule Moved Trigger](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Window/Schedule%20Moved%20Trigger.shtml#1ScriptAnchor_)
- [Window/Window Activation Trigger](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Window/Window%20Activation%20Trigger.shtml#2ScriptAnchor_)

### Blog Entries

- [Extend the context menu for layout and browse mode in FileMaker](https://www.mbsplugins.de/archive/2024-12-11/Extend_the_context_menu_for_la/monkeybreadsoftware_blog_filemaker)
- [Watch MongoDB Database](https://www.mbsplugins.de/archive/2023-11-04/Watch_MongoDB_Database/monkeybreadsoftware_blog_filemaker)
- [Trigger Scripts via WebHook](https://www.mbsplugins.de/archive/2022-12-08/Trigger_Scripts_via_WebHook/monkeybreadsoftware_blog_filemaker)
- [Window Activation Trigger](https://www.mbsplugins.de/archive/2022-10-23/Window_Activation_Trigger/monkeybreadsoftware_blog_filemaker)
- [Script trigger for moving window](https://www.mbsplugins.de/archive/2022-10-07/Script_trigger_for_moving_wind/monkeybreadsoftware_blog_filemaker)
- [OnRecordEdit Trigger in FileMaker](https://www.mbsplugins.de/archive/2022-06-06/OnRecordEdit_Trigger_in_FileMa/monkeybreadsoftware_blog_filemaker)
- [Record Creation Script Trigger](https://www.mbsplugins.de/archive/2020-09-03/Record_Creation_Script_Trigger/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.3pr1](https://www.mbsplugins.de/archive/2019-06-03/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [Comparing Base Elements Plugin to MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-10-24/Comparing_Base_Elements_Plugin/monkeybreadsoftware_blog_filemaker)
- [PHP Functions in MBS Filemaker Plugin](https://www.mbsplugins.de/archive/2012-10-21/PHP_Functions_in_MBS_Filemaker/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 17th April 2026

  
[FM.RunSaveAsXML](FMRunSaveAsXML.md) - [FM.RunScriptIdle](FMRunScriptIdle.md)

[HTML Version](FMRunScript.shtml)