Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  

Applescript.Run

Component: Applescript
Version: 1.0
Mac OS X: Yes
Windows: No
Server: Yes
FileMaker Cloud: No

MBS( "Applescript.Run"; Script Text )

Parameters

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

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.

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:

Variable setzen [ $url ; Wert: "http://www.mbsplugins.com/FMK2015.mp4" ]
Variable setzen [ $r ; Wert: MBS( "Applescript.Run"; "tell application \"VLC\" to GetURL \"" & $url & "\"") ]

See also


Applescript.PropertyCount   -   Applescript.SetPropertyValue

Feedback: Report problem or ask question.




Links
MBS Xojo Chart Plugins