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:
11.0
11.1
11.2
11.3
11.4
11.5
12.0
12.1
12.2
12.3
Statistic
FMM
Blog
AppleScript.Run
The function compiles the AppleScript text and runs it.
Component | Version | macOS | Windows | Linux | Server | iOS SDK | License |
AppleScript | 1.0 | ✅ Yes | ❌ No | ❌ No | ✅ Yes, on macOS | ❌ No | Paid |
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, AppleScript.Execute and AppleScript.Close
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 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 " & 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?\"") ]
See also
- AppleScript.Close
- AppleScript.Compile
- AppleScript.Execute
- WindowsScript.AddCode
- WindowsScript.Close
- WindowsScript.Create
- WindowsScript.ExecuteFunction
- WindowsScript.SetLanguage
Blog Entries
Created 18th August 2014, last changed 15th February 2022
AppleScript.PropertyCount - AppleScript.SetPropertyValue
Feedback: Report problem or ask question.
