Platforms to show: All Mac Windows Linux Cross-Platform

/MacOSX/Spotlight/Query with attributes


Required plugins for this example: MBS MacOSX Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/Spotlight/Query with attributes

This example is the version from Fri, 14th May 2015.

Project "Query with attributes.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change() PushButton2.Enabled=me.ListIndex>=0 PushButton3.Enabled=me.ListIndex>=0 End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Query Inherits TextField
ControlInstance Query Inherits TextField
End Control
Control SearchButton Inherits PushButton
ControlInstance SearchButton Inherits PushButton
EventHandler Sub Action() if q<>nil then q.stop q=nil end if List.DeleteAllRows dim ValuesList(-1) as string = array(MDItemMBS.kMDItemDisplayName, MDItemMBS.kMDItemFSOwnerUserID) q=new MyQuery(query.text, ValuesList) if q.Handle=0 then dim t as string = ReplaceAll(query.text,"""","") q=new MyQuery("* == """+t+"""wcd || kMDItemTextContent = """+t+"""c", ValuesList) end if if q.Handle=0 then MsgBox "Failed to create query" else q.SetMaxCount 100 if q.Execute(q.kMDQueryWantsUpdates) then 'ok q.EnableUpdates else MsgBox "Failed to run query" end if end if End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim list(-1) as Variant = q.ValuesOfAttribute(MDItemMBS.kMDItemDisplayName) dim lines(-1) as string for each v as Variant in List lines.Append v next MsgBox Join(lines,EndOfLine) End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim it as MDItemMBS = List.RowTag(List.ListIndex) dim d as Dictionary = it.GetAttributes(it.AllAttributes) dim lines(-1) as string for each k as Variant in d.Keys dim v as Variant = d.Value(k) if v.IsNull then v="<null>" if v.IsArray then v="<array>" lines.Append k+" -> "+v next MsgBox Join(lines,EndOfLine) End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim it as MDItemMBS = List.RowTag(List.ListIndex) dim v as Variant = it.GetAttribute(it.kMDItemDisplayName) MsgBox v End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() dim count as integer = Q.CountOfResultsWithAttributeValue(MDItemMBS.kMDItemFSOwnerUserID, 501) MsgBox str(Count) End EventHandler
End Control
Control UpdateTimer Inherits Timer
ControlInstance UpdateTimer Inherits Timer
EventHandler Sub Action() List.DeleteAllRows dim items() as MDItemMBS = q.Results for each it as MDItemMBS in items List.AddRow it.DisplayName List.RowTag(List.LastIndex) = it next Title = str(UBound(items)+1)+" items" End EventHandler
End Control
EventHandler Sub Close() if q<>nil then q.stop q=nil end if End EventHandler
Property q As MyQuery
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyQuery Inherits MDQueryMBS
EventHandler Sub Finish() MainWindow.UpdateTimer.Mode = 1 End EventHandler
EventHandler Sub Progress(AddedItems() as MDItemMBS, ChangedItems() as MDItemMBS, RemovedItems() as MDItemMBS) MainWindow.UpdateTimer.Mode = 1 End EventHandler
EventHandler Sub Update(AddedItems() as MDItemMBS, ChangedItems() as MDItemMBS, RemovedItems() as MDItemMBS) MainWindow.UpdateTimer.Mode = 1 End EventHandler
End Class
End Project

See also:

The items on this page are in the following plugins: MBS MacOSX Plugin.


The biggest plugin in space...