Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
The function compiles the AppleScript text and runs it.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
AppleScript | 1.0 | ✅ Yes | ❌ No | ❌ No | ✅ Yes, on macOS | ❌ No |
Parameter | Description | Example |
---|---|---|
Script Text | This is the text of the script to run | "3 + 4" |
Returns result of script.
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 " & Quote(ScriptName);
VBScriptText =
"FUNCTION DoFMSCript(FileName, ScriptName)" & "¶" &
"Set fmApp = CreateObject(\"FMPro.Application\")" & "¶" &
"fmApp.Visible = True" & "¶" &
"Set fmDocs = fmApp.Documents" & "¶" &
"For Each fmDoc In fmDocs" & "¶" &
"If InStr(LCase(fmDoc.fullname), LCase(FileName)) > 0 Then" & "¶" &
" fmDoc.dofmscript (ScriptName)" & "¶" &
"End If" & "¶" &
"Next" & "¶" &
"END FUNCTION";
ScriptID = MBS("WindowsScript.Create");
lang= MBS("WindowsScript.SetLanguage"; ScriptID; "VBScript");
addcode = MBS("WindowsScript.AddCode"; ScriptID; VBScriptText)
];
Case(
Get ( SystemPlatform ) = 1;
// Mac OSX Case
MBS(
"Applescript.Run";
Applescript
);
// Windows Case
MBS("WindowsScript.ExecuteFunction";ScriptID; "DoFMScript";FileName; ScriptName) &
MBS("WindowsScript.Close"; ScriptID)
)
)
Create A Folder
Let(
[
/*-----------------PARAMETERS--------------------*/
folderName = "My New Folder";
scriptText =
"set folder_name to " & Quote(folderName) & "¶" &
"tell application " & Quote("Finder") & "¶" &
" set f to make new folder at desktop" & "¶" &
" set the name of f to folder_name" & "¶" &
"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\"" & "¶" &
" set the_list to \"\"" & "¶" &
" set person_list to the name of every person" & "¶" &
" repeat with this_name in person_list" & "¶" &
" set the_list to the_list & this_name & return" & "¶" &
" end repeat" & "¶" &
"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 " & Quote(theScriptName);
VBScriptText =
"FUNCTION DoFMSCript(FileName, ScriptName)" & "¶" &
"Set fmApp = CreateObject(\"FMPro.Application\")" & "¶" &
"fmApp.Visible = True" & "¶" &
"Set fmDocs = fmApp.Documents" & "¶" &
"For Each fmDoc In fmDocs" & "¶" &
"If InStr(LCase(fmDoc.fullname), LCase(FileName)) > 0 Then" & "¶" &
" fmDoc.dofmscript (ScriptName)" & "¶" &
"End If" & "¶" &
"Next" & "¶" &
"END FUNCTION";
ScriptID = MBS("WindowsScript.Create");
lang= MBS("WindowsScript.SetLanguage"; ScriptID; "VBScript");
addcode = MBS("WindowsScript.AddCode"; ScriptID; VBScriptText)
];
Case(
Get ( SystemPlatform ) = 1;
// Mac OSX Case
MBS(
"Applescript.Run";
Applescript
);
// Windows Case
MBS("WindowsScript.ExecuteFunction";ScriptID; "DoFMScript";theFileName; theScriptName) &
MBS("WindowsScript.Close"; ScriptID)
)
Open URL in VLC player:
Set Variable [ $url ; Value: "http://www.mbsplugins.com/FMK2015.mp4" ]
Set Variable [ $r ; Value: MBS( "Applescript.Run"; "tell application \"VLC\" to GetURL \"" & $url & "\"") ]
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 \"" & $text & "\" using \"" & $voice & "\" speaking rate " & $rate & " pitch " & $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")
This function checks for a license.
Created 18th August 2014, last changed 2nd December 2022