Platforms to show: All Mac Windows Linux Cross-Platform
/MacFrameworks/FSEvents/FSEvents New Files in Documents
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/FSEvents/FSEvents New Files in Documents
This example is the version from Sat, 22th Dec 2023.
Project "FSEvents New Files in Documents.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
EventHandler Sub DoubleClick()
If Me.ListIndex < Me.ListCount Then
Dim path As String = Me.List(Me.ListIndex)
Dim f As FolderItem = GetFolderItem(path)
if f <> nil then
f.parent.launch
end if
End If
End EventHandler
End Control
EventHandler Sub Close()
f.stop
End EventHandler
EventHandler Sub Open()
Dim eventid As UInt64
dim flags as integer
dim latency as Double
// we watch for new files
eventid=FSEventsMBS.GetCurrentEventId
flags=FSEventsMBS.kFSEventStreamCreateFlagIgnoreSelf +_
FSEventsMBS.kFSEventStreamEventFlagItemCreated +_
FSEventsMBS.kFSEventStreamCreateFlagFileEvents
latency=1.0
f=New FSEvents(SpecialFolder.Documents, eventid, latency, flags)
f.list = listbox1
// show description for debugging
'MsgBox f.Description
// and on console (stderr)
'f.Show
if not f.Start then
MsgBox "Failed to start."
end if
End EventHandler
Property f As fsevents
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class FSEvents Inherits FSEventsMBS
EventHandler Sub Callback(index as integer, count as integer, path as string, flags as integer, eventID as UInt64)
// skip duplicates
If Right(path,9) = ".DS_Store" Then Return
If path = lastPath Then Return
lastpath = path
list.insertRow 0,path
// avoid list getting too full
If list.ListCount > 100 Then
list.RemoveRow 100
End If
End EventHandler
Property List As listbox
Property Private lastPath As string
End Class
Sign
End Sign
End Project
See also:
The items on this page are in the following plugins: MBS MacFrameworks Plugin.