# Define a hotkey to copy field name for layout objects in FileMaker

**URL:** <https://the.fmsoup.org/t/define-a-hotkey-to-copy-field-name-for-layout-objects-in-filemaker/4460>\
**Category:** MBS Plugins\
**Tags:** layout-design, integration, filemaker\
**Created:** [November 11, 2024, 9:41am UTC](https://the.fmsoup.org/t/define-a-hotkey-to-copy-field-name-for-layout-objects-in-filemaker/4460 "2024-11-11T09:41:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/monkeybreadsoftware/32/361_2.png) [@MonkeybreadSoftware](https://the.fmsoup.org/u/MonkeybreadSoftware)\
**Post date:** [November 11, 2024, 9:41am UTC](https://the.fmsoup.org/t/define-a-hotkey-to-copy-field-name-for-layout-objects-in-filemaker/4460/1 "2024-11-11T09:41:15Z")

</div>

Let's help a few FileMaker developers using FileMaker a lot to edit layouts. Sometimes you may want to get the field name for a layout object. Whether you like to paste it to ChatGPT to use the names or you just need to know what field to use for a calculation, a hotkey to get the field name into the clipboard can be very useful.

To do this job, we need a little calculation to evaluate at runtime in the layout editor. This would be a Let statement to do four things:

First we need to run the copy command in FileMaker's Edit menu. To learn the command codes, please use [Menubar.ListMenuCommands](https://www.mbsplugins.eu/MenubarListMenuCommands.shtml) to scan the menu bar. In the [Menubar.RunMenuCommand](https://www.mbsplugins.eu/MenubarRunMenuCommand.shtml) function our plugin will locate the menu item and ask it to perform the action. Please note that you can't run this while a script is performing as the menu command is then blocked. But you can of course use our [Schedule](https://www.mbsplugins.eu/component_Schedule.shtml)functions to run it later and then also schedule another script to run a second later.

Once completed, we check the clipboard for something copied with [Clipboard.GetFileMakerData](https://www.mbsplugins.eu/ClipboardGetFileMakerData.shtml) function. Passing Auto to the function as mode makes live easier as the plugin will just check what is available in the clipboard. But we are only interested in layout objects, so we could also pass Layout there.

Next we search the XML with [XML.Query](https://www.mbsplugins.eu/XMLQuery.shtml) function. The query goes down the path from the snippet to the layout, the object on the layout, then into the Field Object to get the name entry. Since you can select multiple entries, the result is a list and we ask the plugin with flag 2 to return as text list without the XML nodes.

Last we use [Clipboard.SetText](https://www.mbsplugins.eu/ClipboardSetText.shtml) to put the list on the clipboard, so you can paste it somewhere else. Here is the full calculation:

```auto
Let([
copy = MBS( "Menubar.RunMenuCommand"; 57634 );
xml = MBS( "Clipboard.GetFileMakerData"; "Auto" );
name = MBS("XML.Query"; xml; "/fmxmlsnippet/Layout/Object/FieldObj/Name"; ""; 2);
r = MBS( "Clipboard.SetText"; name )
]; name)

```

Next we need to escape the quotes with backslashes. Then we can use for the [HotKey.SetEvaluate](https://www.mbsplugins.eu/HotKeySetEvaluate.shtml) call. To register the hotkey we call [Hotkey.Register](https://www.mbsplugins.eu/HotKeyRegister.shtml) and pass whatever code you like to press. The example below defines option-control-command-c as key combination. Here is the script:

```auto
# registers a hotkey option-control-command-c to copy the names of fields referenced by selected layout objects in the layout editor
Set Variable [$Hotkey ; Value: MBS("Hotkey.Register"; "C"; "option control command")]
# set calculation to run
Set Variable [ $r ; Value: MBS("HotKey.SetEvaluate"; $Hotkey; "Let([
copy = MBS( \"Menubar.RunMenuCommand\"; 57634 );
xml = MBS( \"Clipboard.GetFileMakerData\"; \"Auto\" );
name = MBS(\"XML.Query\"; xml; \"/fmxmlsnippet/Layout/Object/FieldObj/Name\"; \"\"; 2);
r = MBS( \"Clipboard.SetText\"; name )
]; name)") ]
# make it permanent and go to the preferences file
Set Variable [$r ; Value: MBS( "HotKey.SetPermanent"; $HotKey; 1 )]

```

Please try. You may just add this to a database as a script and run it to install the command. The example file Hotkeys.fmp12 is included with our plugin download and includes the script above to copy. Download here: [Hotkeys.zip](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/HotKeys.zip) Have fun!
