Skip to main content

Get Icons into FileMaker Pro

By December 22, 2016September 26th, 2017FileMaker Plug-ins blog

With Troi File Plug-in 8.6 for FileMaker Pro you can easily add the icons of files on your disk to your FileMaker app.

To do this you use the TrFile_GetIcon function. It can create icons in sizes varying from 16×16 to 1024×1024 pixels and even with double resolution for retina screens.

You can get the icon like this:

Set Variable [ $Icon; TrFile_GetIcon(  iconSwitches ; filePath ) ]

The TrFile_GetIcon function has 2 parameters: switches and the filepath of the file you want to get the icon of. With the switches parameter you can specify the size of the icon.

All you need is a simple script

A simplified “Get Icon from file path” script looks like this:

Set Variable [ $FilePath_forIcon; Get( ScriptParameter ) ]
Set Variable [ $Icon; TrFile_GetIcon( “-size=64” ; $FilePath_forIcon ) ]
Set Variable [ $ErrorCode; Value:GetAsText( $Icon )  // get a possible error code ]
#Check if there was an error:
If [ Left($ErrorCode ; 2) <> “$$” ]
#There is no error, clean it up:
Set Variable [ $ErrorCode; Value:0 ]
Show Custom Dialog [ “An error occurred. Error code =” & $ErrorCode; “OK” ]
End If
#Save the results into your fields:
Set Field [ this::icon64x64; $Icon ]
Set Field [ this::gErrorCode; $ErrorCode ]
Exit Script [ Result: $ErrorCode ]

You supply the file path to the script as a script parameter, for example “C:\Data\Report.doc” on Windows or “Mac HD:Data:Report.doc on Mac OS X.

By integrating this script into your solution you can show the real file icons,  providing your users with a rich experience.

In the download of the Troi File Plug-in you find the Thumbnail.fmp12 file with more example scripts:

Runs on Windows 10 and macOS Sierra

Troi File Plug-in runs on Windows 10, 8.1, 8 and 7 and is also compatible with macOS Sierra, Mac OS X 10.11 (El Capitan), up to 10.6.x (Snow Leopard).
You can use this version with FileMaker Pro 15, 14, 13 and 12.

Get your Troi File Plug-in here