Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Adds a new command for contextual menu.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
SyntaxColoring | 9.5 | ✅ Yes | ❌ No | ❌ No | ❌ No | ❌ No |
Parameter | Description | Example | Flags |
---|---|---|---|
Title | The title for the menu command. If multi line, we build submenus based on the path descripted. If title is just "-", we add a separator. |
"MyCommands¶Hello" | |
Expression | The expression to evaluate in FileMaker when menu command is choosen. | ||
InstallWhen | Whether to enable only if selection is present. 0: always on (default) 1: need no row selected 2: need exactly one row selected 3: need one or more rows selected 4: need all rows selected Add 8 to allow for discontinuous selections (in version 10.0 or later). |
0 | Optional |
keyEquivalent | Available in MBS FileMaker Plugin 10.0 or newer. The key equivalent. Is shown right in the menu and can be pressed while menu is open. |
"T" | Optional |
KeyEquivalentModifierMask | Available in MBS FileMaker Plugin 10.0 or newer. The menu items's keyboard equivalent modifiers. NSShiftKeyMask is a valid modifier for any key equivalent in mask. This allows you to specify key-equivalents such as Command-Shift-1 that are consistent across all keyboards. However, with a few exceptions (such as the German "ß” character), a lowercase character with NSShiftKeyMask is interpreted the same as the uppercase character without that mask. For example, Command-Shift-c and Command-C are considered to be identical key equivalents. NSShiftKeyMask 131072 Shift Key NSControlKeyMask 262144 Control Key NSAlternateKeyMask 524288 Alternate/Option Key NSCommandKeyMask 1048576 Command Key |
524288 + 131072 | Optional |
Returns OK or error.
Add a greeting command:
MBS( "SyntaxColoring.AddContextMenuCommand"; "Greeting"; "MBS(\"Msgbox\"; \"Hello World\")"; 0 )
Add a rename command for variable:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Rename $I to $counter";
"Let ([ r = MBS( \"Menubar.RunMenuCommand\"; 57634 /* copy */ ); xml = MBS( \"Clipboard.GetFileMakerData\"; \"ScriptStep\" ); xml = Substitute ( xml; \"$i\"; \"$counter\"); r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml ); r = MBS( \"Menubar.RunMenuCommand\"; 57637 /* paste */ ) ]; \"\" )"; 0 )
Add an insert loop command:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Insert For Loop";
"Let ([
xml = \"<fmxmlsnippet type=\\\"FMObjectList\\\"><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>loop counting up from 1 to $count</Text></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[\\\"/* add count here */\\\"]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$count</Name></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[1]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$index</Name></Step><Step enable=\\\"True\\\" id=\\\"68\\\" name=\\\"If\\\"><Calculation><![CDATA[$index ≤ $count]]></Calculation></Step><Step enable=\\\"True\\\" id=\\\"71\\\" name=\\\"Loop\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>your script steps here</Text></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>next</Text></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[$index + 1]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$index</Name></Step><Step enable=\\\"True\\\" id=\\\"72\\\" name=\\\"Exit Loop If\\\"><Calculation><![CDATA[$index > $count]]></Calculation></Step><Step enable=\\\"True\\\" id=\\\"73\\\" name=\\\"End Loop\\\"></Step><Step enable=\\\"True\\\" id=\\\"70\\\" name=\\\"End If\\\"></Step></fmxmlsnippet>\";
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
r = MBS( \"Menubar.RunMenuCommand\"; 57637 /* paste */ )
]; \"\" )"; 0 )
Add a search and replace command:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Search and Replace";
"Let ([
/* ask for search text via dialog */
ResetResult = MBS( \"Dialog.Reset\" );
ClearResult = MBS( \"Dialog.ClearFields\" );
MessageResult = MBS( \"Dialog.SetMessage\"; \"Search and replace in script:\" );
InfoResult = MBS( \"Dialog.SetInformativeText\"; \"Search text can include XML tags.\" );
Field1Result = MBS( \"Dialog.AddField\"; \"Search for:\" );
Field2Result = MBS( \"Dialog.AddField\"; \"Replace with:\" );
Button1Result = MBS( \"Dialog.SetDefaultButton\"; \"Replace\");
Button2Result = MBS( \"Dialog.SetAlternateButton\"; \"Cancel\");
DialogResult = MBS( \"Dialog.Run\" );
SearchText = MBS( \"Dialog.GetFieldText\"; 0 );
ReplaceText = MBS( \"Dialog.GetFieldText\"; 1 );
/* do replace */
r = If(DialogResult = \"Replace\"; Let([
/* copy script steps */
r = MBS( \"Menubar.RunMenuCommand\"; 57634 );
/* get XML from clipboard */
xml = MBS( \"Clipboard.GetFileMakerData\"; \"ScriptStep\" );
/* search and replace */
xml = Substitute ( xml; SearchText; ReplaceText);
/* put XML back on clipboard */
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
/* paste script steps */
r = MBS( \"Menubar.RunMenuCommand\"; 57637 )
]; 1))
];1)"; 3 )
Add an insert JSONSetElement command:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Insert set variable for JSONSetElement";
"Let ([
xml = \"<fmxmlsnippet type=\\\"FMObjectList\\\"><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Variable setzen\\\"><Value><Calculation><![CDATA[JSONSetElement ( \" & Char(10) & \" \\\"{}\\\" ;\" & Char(10) & \" [ \\\"keyOrIndexOrPath\\\" ; \\\"value\\\" ; JSONString ] ;\" & Char(10) & \" [ \\\"keyOrIndexOrPath\\\" ; \\\"value\\\" ; JSONString ]¶)]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$json</Name></Step></fmxmlsnippet>\";
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
r = MBS( \"Menubar.RunMenuCommand\"; 57637 /* paste */ )
]; \"\" )"; 0 )
// we use Char(10) to get the new line in the XML. And we use \\\ to escape quotes in escaped calculation.
Add menu command to write script to desktop:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Write script to desktop";
"MBS( \"Text.WriteTextFile\";
MBS( \"ScriptWorkspace.ScriptText\" );
MBS( \"Path.AddPathComponent\";
MBS( \"Folders.UserDesktop\" );
\"Script \" & substitute(substitute(MBS( \"ScriptWorkspace.CurrentTab\" ); \":\"; \"-\"); \"/\"; \"-\") & \".txt\" );
\"UTF-8\"
)"; 0 )
Add separator item:
MBS( "SyntaxColoring.AddContextMenuCommand"; "-"; "-"; 0 )
// needs version 10.0 of the plugin.
Add function header:
MBS( "SyntaxColoring.AddContextMenuCommand";
"Insert function header";
"Let ([
xml = \"<fmxmlsnippet type=\\\"FMObjectList\\\"><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>Description</Text></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>Author</Text></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>Modifications</Text></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"85\\\" name=\\\"Allow User Abort\\\"><Set state=\\\"False\\\"></Set></Step><Step enable=\\\"True\\\" id=\\\"86\\\" name=\\\"Set Error Capture\\\"><Set state=\\\"True\\\"></Set></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[Get(ScriptParameter)]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$param</Name></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[\\\"\\\"]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$result</Name></Step><Step enable=\\\"True\\\" id=\\\"103\\\" name=\\\"Exit Script\\\"><Calculation><![CDATA[$result]]></Calculation></Step></fmxmlsnippet>\";
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
r = MBS( \"Menubar.RunMenuCommand\"; 57637 /* paste */ )
]; \"\" )"; 0 )
Add command to paste snippet from folder picked by dialog:
// put snippets as xml files into ~/Library/Application Support/FileMaker/Snippets folder.
MBS( "SyntaxColoring.AddContextMenuCommand";
"Insert snippet from snippet folder";
"Let([
Path = MBS( \"Path.AddPathComponent\"; MBS( \"Folders.UserHome\" ); \"Library\"; \"Application Support\"; \"FileMaker\"; \"Snippets\");
Files = MBS( \"Files.List\"; Path; 1+4);
Names = MBS( \"List.RemovePostfix\"; Files; \".xml\"; 1);
r = MBS( \"ListDialog.Reset\" ) & MBS( \"ListDialog.AddItemsToList\"; Names; Files) & MBS( \"ListDialog.SetPrompt\"; \"Choose snippet to insert:\" );
answer = MBS( \"ListDialog.ShowDialog\" );
r = If(answer = \"OK\"; MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; MBS( \"Text.ReadTextFile\"; MBS( \"Path.AddPathComponent\"; Path; MBS( \"ListDialog.GetSelectedTag\" )); \"UTF-8\") ) & MBS( \"Menubar.RunMenuCommand\"; 57637 /* paste */ ))]; 0)"; 0 )
Add duplicate context menu entry:
MBS( "SyntaxColoring.AddContextMenuCommand"; "Duplicate";
"Let ([ r = MBS( \"Menubar.RunMenuCommand\"; 49182 /* duplicate */ )]; \"\" )"; 3 )
This function is free to use.
Created 18th October 2019, last changed 14th July 2022