AppleScript.Run
---------------

The function compiles the AppleScript text and runs it.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [AppleScript](component_AppleScript.md) | [1.0](newinversion10.md) | ✅ Yes | ❌ No | ❌ No | ✅ Yes, on macOS | ❌ No |

MBS( "AppleScript.Run"; Script Text ) 

**MBS**( **"AppleScript.Run";** /\* The function compiles the AppleScript text and runs it. \*/  
**$Script Text**) /\* This is the text of the script to rune.g. "3 + 4" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Script Text | This is the text of the script to run | "3 + 4" |

### Result

Returns result of script.

### Description

The function compiles the AppleScript text and runs it.  
Any Result returned by the AppleScript is returned as the result of the calculation. This is similar to the Script Results that were introduced in FileMaker 8.0. This is much easier then using [AppleScript.Compile](AppleScriptCompile.md), [AppleScript.Execute](AppleScriptExecute.md) and [AppleScript.Close](AppleScriptClose.md)  
  
Older plugin versions used to put quotes around result. 6.4 and newer don't include quotes.  
  
This function does return "" in case AppleScript fails. If you need more error handling, please run [AppleScript.Compile](AppleScriptCompile.md) to get compile error for syntax errors.  
### Examples

Trigger a FileMaker Script Using OS Scripting

 Let(  
\[  
// --- the name of the script to run ------------------  
  
ScriptName = "Triggered Script";  
FileName = Get(FileName);  
  
//------------------------------------------------------------  
  
//--- don't need to edit anything below this line --------  
  
  
Applescript = "do script " &amp; Quote(ScriptName);  
  
VBScriptText =   
"FUNCTION DoFMSCript(FileName, ScriptName)" &amp; "¶" &amp;   
  
"Set fmApp = CreateObject(\\"FMPro.Application\\")" &amp; "¶" &amp;   
"fmApp.Visible = True" &amp; "¶" &amp;   
"Set fmDocs = fmApp.Documents" &amp; "¶" &amp;  
"For Each fmDoc In fmDocs" &amp; "¶" &amp;  
"If InStr(LCase(fmDoc.fullname), LCase(FileName)) &gt; 0 Then" &amp; "¶" &amp;  
" fmDoc.dofmscript (ScriptName)" &amp; "¶" &amp;  
"End If" &amp; "¶" &amp;  
"Next" &amp; "¶" &amp;  
  
"END FUNCTION";  
  
ScriptID = MBS ("[WindowsScript.Create](WindowsScriptCreate.md)");  
lang= MBS ("[WindowsScript.SetLanguage](WindowsScriptSetLanguage.md)"; ScriptID; "VBScript");  
addcode = MBS ("[WindowsScript.AddCode](WindowsScriptAddCode.md)"; ScriptID; VBScriptText)  
  
\];  
Case(  
Get ( SystemPlatform ) = 1;  
  
// Mac OSX Case  
MBS (   
"Applescript.Run";  
Applescript  
);  
  
// Windows Case  
MBS ("[WindowsScript.ExecuteFunction](WindowsScriptExecuteFunction.md)";ScriptID; "DoFMScript";FileName; ScriptName) &amp;   
MBS ("[WindowsScript.Close](WindowsScriptClose.md)"; ScriptID)  
  
)  
)  
  
Create A Folder

 Let(  
\[  
/\*-----------------PARAMETERS--------------------\*/  
folderName = "My New Folder";  
  
scriptText =   
"set folder\_name to " &amp; Quote(folderName) &amp; "¶" &amp;  
"tell application " &amp; Quote("Finder") &amp; "¶" &amp;   
" set f to make new folder at desktop" &amp; "¶" &amp;   
" set the name of f to folder\_name" &amp; "¶" &amp;   
"end tell"  
  
\];  
/\*-------------------FUNCTION----------------------\*/  
MBS (   
"Applescript.Run";  
scriptText  
)  
)  
  
/\*------------------------------------------/  
Creates a folder called "My New Folder on the users desktop  
\*/  
Get Names From Address Book

 Let(  
\[  
/\*-----------------PARAMETERS--------------------\*/  
scriptText =   
"tell application \\"Address Book\\"" &amp; "¶" &amp;   
" set the\_list to \\"\\"" &amp; "¶" &amp;  
" set person\_list to the name of every person" &amp; "¶" &amp;  
" repeat with this\_name in person\_list" &amp; "¶" &amp;  
" set the\_list to the\_list &amp; this\_name &amp; return" &amp; "¶" &amp;  
" end repeat" &amp; "¶" &amp;   
"end tell"  
  
\];  
/\*-------------------FUNCTION----------------------\*/  
MBS (   
"Applescript.Run";  
scriptText  
)  
)  
  
/\*------------------------------------------/  
Creates a folder called "My New Folder on the users desktop  
\*/  
Trigger A FileMaker Script (Custom Function)

 MBS\_TriggerScript ( "Triggered Script" ; Get ( FileName ) )   
  
  
Custom Function Definition  
/\*###############################################  
  
MBS\_TriggerScript  
created 10/26/06, by Todd Geist, todd@geistinteractive.com  
  
Parameters: theScriptName, theFileName  
  
Dependancies: MBS FileMaker Plug-in.  
  
Notes: Uses VBScript and Applescript to run a script  
  
\################################################\*/   
Let(  
\[  
  
Applescript = "do script " &amp; Quote(theScriptName);  
  
VBScriptText =   
"FUNCTION DoFMSCript(FileName, ScriptName)" &amp; "¶" &amp;   
  
"Set fmApp = CreateObject(\\"FMPro.Application\\")" &amp; "¶" &amp;   
"fmApp.Visible = True" &amp; "¶" &amp;   
"Set fmDocs = fmApp.Documents" &amp; "¶" &amp;  
"For Each fmDoc In fmDocs" &amp; "¶" &amp;  
"If InStr(LCase(fmDoc.fullname), LCase(FileName)) &gt; 0 Then" &amp; "¶" &amp;  
" fmDoc.dofmscript (ScriptName)" &amp; "¶" &amp;  
"End If" &amp; "¶" &amp;  
"Next" &amp; "¶" &amp;  
  
"END FUNCTION";  
  
ScriptID = MBS ("[WindowsScript.Create](WindowsScriptCreate.md)");  
lang= MBS ("[WindowsScript.SetLanguage](WindowsScriptSetLanguage.md)"; ScriptID; "VBScript");  
addcode = MBS ("[WindowsScript.AddCode](WindowsScriptAddCode.md)"; ScriptID; VBScriptText)  
  
\];  
Case(  
Get ( SystemPlatform ) = 1;  
  
// Mac OSX Case  
MBS (   
"Applescript.Run";  
Applescript  
);  
  
// Windows Case  
MBS ("[WindowsScript.ExecuteFunction](WindowsScriptExecuteFunction.md)";ScriptID; "DoFMScript";theFileName; theScriptName) &amp;   
MBS ("[WindowsScript.Close](WindowsScriptClose.md)"; ScriptID)  
  
)  
Open URL in VLC player:

 Set Variable \[ $url ; Value: "https://www.monkeybreadsoftware.com/filemaker/video/FMK2015.mp4" \]   
Set Variable \[ $r ; Value: MBS ( "Applescript.Run"; "tell application \\"VLC\\" to GetURL \\"" &amp; $url &amp; "\\"") \]  
Speak using AppleScript:

 Set Variable \[ $text ; Value: "Hello \\"Test\\"" \]   
Set Variable \[ $voice ; Value: "Daniel" \]   
Set Variable \[ $rate ; Value: 100 \]   
Set Variable \[ $pitch ; Value: 60 \]   
  
Set Variable \[ $text ; Value: Substitute($text ; "\\""; "\\\\\\"") \]   
Set Variable \[ $r ; Value: MBS ( "AppleScript.Run"; "say \\"" &amp; $text &amp; "\\" using \\"" &amp; $voice &amp; "\\" speaking rate " &amp; $rate &amp; " pitch " &amp; $pitch ) \]  
Show dialog:

 Set Variable \[ $r ; Value: MBS ("AppleScript.Run"; "display dialog \\"Did I start yet?\\"") \]  
Get sender of current email in Mail:

 MBS ( "AppleScript.Run";   
"tell application \\"Mail\\"¶  
 set theSelection to selection¶  
 set theMessage to item 1 of theSelection¶  
 return sender of theMessage as Unicode text¶  
end tell")  
Get content of current email in Mail:

 MBS ( "AppleScript.Run";   
"tell application \\"Mail\\"¶  
 set theSelection to selection¶  
 set theMessage to item 1 of theSelection¶  
 return content of theMessage as Unicode text¶  
end tell")  
Get a list of reminders:

 MBS ("Applescript.Run"; "tell application \\"Reminders\\" to return name of reminders of list \\"Gäste\\" as text")  
### See also

- [AppleScript.Close](AppleScriptClose.md)
- [AppleScript.Compile](AppleScriptCompile.md)
- [AppleScript.Execute](AppleScriptExecute.md)
- [AppleScript.List](AppleScriptList.md)
- [WindowsScript.AddCode](WindowsScriptAddCode.md)
- [WindowsScript.Close](WindowsScriptClose.md)
- [WindowsScript.Create](WindowsScriptCreate.md)
- [WindowsScript.ExecuteFunction](WindowsScriptExecuteFunction.md)
- [WindowsScript.SetLanguage](WindowsScriptSetLanguage.md)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 24 - Merry Christmas with Apple Script](https://www.mbsplugins.de/archive/2024-12-24/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [4000 functions in 10 years](https://www.mbsplugins.de/archive/2016-06-11/4000_functions_in_10_years/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 30th September 2025

  
[AppleScript.PropertyCount](AppleScriptPropertyCount.md) - [AppleScript.SetPropertyValue](AppleScriptSetPropertyValue.md)

[HTML Version](AppleScriptRun.shtml)