« Checking plugin versi… | Home | MBS Xojo Plugins, ver… »

Spotlight search in FileMaker with MBS Plugin

We got a nice new search feature for our MBS FileMaker Plugin. You can create searches, run them and query results. Here is an example script to search all applications:

Set Variable [ $query ; Value: MBS( "MetaDataQuery.Create" ) ] 

Set Variable [ $r ; Value: MBS( "MetaDataQuery.SetQueryString"; $Query; "kMDItemContentType=\"com.apple.application-bundle\"") ] 

Set Variable [ $r ; Value: MBS( "MetaDataQuery.StartQuery"; $Query) ] 

# Wait for search to finish

Loop

Pause/Resume Script [ Duration (seconds): ,2 ] 

Exit Loop If [ MBS( "MetaDataQuery.IsGathering"; $Query ) = 0 ] 

End Loop

# Stop

Set Variable [ $r ; Value: MBS( "MetaDataQuery.StopQuery"; $Query) ] 

Delete All Records [ With dialog: Off ]

# Put global result on top:

Set Field [ Search Applications::All Results JSON ; MBS( "MetaDataQuery.Results"; $Query ) ] 

Set Variable [ $Count ; Value: MBS( "MetaDataQuery.ResultCount"; $Query ) ] 

Set Field [ Search Applications::ResultCount ; $Count ] 

# And show records:

Set Variable [ $index ; Value: 0 ] 

Loop

New Record/Request

Set Variable [ $path ; Value: MBS( "MetaDataQuery.PathAtIndex"; $Query; $Index ) ] 

Set Variable [ $result ; Value: MBS( "MetaDataQuery.ResultAtIndex"; $Query; $Index ) ] 

Set Field [ Search Applications::Name ; MBS( "Files.FileDisplayName"; $Path ) ] 

Set Field [ Search Applications::FilePath ; $path ] 

Set Field [ Search Applications::Attributes JSON ; $result ] 

Set Field [ Search Applications::Icon ; MBS( "Icon.GetIcon"; $Path; 128 ) ] 

Commit Records/Requests [ With dialog: Off ] 

# next

Set Variable [ $index ; Value: $index + 1 ] 

Exit Loop If [ $index ≥ $count ] 

# Lets exit when we have 100 items

Exit Loop If [ $index > 100 ] 

End Loop

Set Variable [ $r ; Value: MBS( "MetaDataQuery.Close"; $Query ) ] 

As you see, we create a new query. Than we set the query string where we check if content type is an application. We start the search which runs asynchronously in the background. For this example we use a loop to wait for the search to finish getting results. Than we stop query and check results. For the results, we give you two ways: You can have all the attributes as JSON or you just get the file path of the item.

The example database here shows the applications in records. We put in the icon of the application, show the display name, the path. The JSON is also stored and can be inspected. Please try with next prerelease and let us know whether you like it.

16 12 17 - 18:52