TrFile_DragAndDrop (function reference)

By May 1, 2017May 21st, 2020Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_DragAndDrop
Troi File Plug-in for FileMaker Pro


This function implements drag and drop of files and folders onto a FileMaker window.

SyntaxFunction badge

TrFile_DragAndDrop ( switches ; fileName ; scriptName ; { fieldBounds } )


switches determine the behavior of the function
fileName the name of the file that contains the script to be triggered
scriptName the name of the script to be triggered when files/folders are dropped on a window
fieldBounds (optional) a rectangle on the layout where the drag is accepted. Dimensions (in pixels) are in this order: "left top right bottom", which is the same order as the FileMaker FieldBounds function returns


switches can be one of this:

-AddDragAndDropHandler the plug-in starts accepting drag and drop. You can now drag files on the window
-StopDragAndDrop the plug-in no longer accepts drag and drop

You can also add one of these switches

-LinkCursor (default) while dragging show an arrow cursor with a small link symbol
-CopyCursor while dragging show arrow cursor with a small plus symbol

These 2 switches only change how the cursor looks. In the triggered script you need to implement any action you want to perform on the dragged items.

You can also add:

-AllowMailDrops this will allow emails (from the OS X to be dragged to FileMaker
-ScrollDropZone when you use a drop zone for the drag destination and add this switch, the position of the dropzone will scroll too when scrolling the FileMaker window
-BringToFront brings the FileMaker application to the front before triggering the trigger script.

Returned Result

Data type returned

Error code


The returned result is an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:

0 no error
$$-50 paramErr there was an error with a parameter
$$-5600 errInvalidWindowRef the window could not be found
$$-4223 errTooManyEvents you have specified more than 3 D&D handlers

Other errors may be returned.

Originated in

Troi File Plug-in 4.6


FileMaker Pro 15 to 19


You can now specify three separate drag destinations, by calling the function three times with the switch -AddDragAndDropHandler with the 3 rectangles you want as drop zones.

The FileMaker window that is in front when the “-AddDragAndDropHandler” switch is executed, will be activated as the destination of future drags.

When the plug-in detects a drag on the destination window, the specified script will be triggered. The (incoming) ScriptParameter of the triggered script will contain the list of files/folders that were dragged on the window.

You can drag one or more files and folders (or a mix of this) on the window. The trigger script should be expecting this and be capable to handle this, for example in a loop. Alternatively the script can only use the first file in the list.

See the switch “-PackageFolderAttr” in the function TrFile_GetFileAttribute: this can be used to determine if a result of the drag and drop action is a package.

– The plug-in is not aware if the position of the custom fieldbounds is changed, for example when scrolled. Use the -ScrollDropZone switch to have the position of the dropzone automatically adjusted when scrolling the FileMaker window
– (macOS) the drop box highlight is only visible over a white background.
– (macOS) the link and copy cursor is visible only when moving the cursor.


To make drag and drop work you need a trigger script that handles the drag. Also you need to start and stop the plug-in handling the drags. We here create a (simplified) script that will put the path of first file found in a field. See the example files for a more extensive script handling more files and container fields.

– Create a script named “DragTriggerscript”:

Set Variable [ $pathList ; Value : Get ( ScriptParameter ) ] 
If [ Get ( FoundCount ) = 0 ] 
    New Record/Request 
End If 
Set Variable [ $returnPos ; Value : Position ( $pathList ; "¶" ; 1 ; 1 ) ] 
Set Field [ this::onepath ; Value : If ( $returnPos > 0 ; Left ( $pathList ; $returnPos - 1 ) ; $pathList ) ] 
## here you can add actions you want to perform on this file

– Starting drag and drop can be done like this:

Set Field [ gErrorCode ; TrFile_DragAndDrop ( "-AddDragAndDropHandler" ; Get ( FileName ) ;
			"DragTriggerscript" ) ]

After this step has been executed the user can drag files on the window and the DragTriggerScript will be run.

– Stopping drag and drop can be done like this:

Set Field [ gErrorCode ; TrFile_DragAndDrop ( "-StopDragAndDrop" ; "" ; "" ) ]

Example 2

Set Variable [ $containerFieldBounds ; FieldBounds ( Get ( FileName ) ; Get ( LayoutName ) ; 
			Get ( ActiveFieldName ) ) ]
Set Variable [ $result ; TrFile_DragAndDrop ( "-AddDragAndDropHandler" ; Get ( FileName ) ; 
			"DragTriggerscript" ; $containerFieldBounds ) ]

This will make the drag area around a container field. It works in FileMaker 10 and later. In previous versions of FileMaker you need to correct for the status area on the left. See the scripts in the example file DragAndDrop for this.

Related functionFunction badge


Related script stepScript step badge

Add DragAndDrop Handler

Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 15 to 19 –> TrFile_DragAndDrop (filep4298) 2020-0520 15:29:27