FolderItem property for macOS "nobrowse" option?

Hi All,

I’m running into an issue where I need to mask the “special” volumes created on modern macOS from the user when parsing the mounted volumes. The “mount” command lists all of these special volumes as “nobrowse”. Is there a way to determine that from the FolderItem object returned for those volumes?

I See we have a NSURLVolumeIsBrowsableKey method for getResourceValue in NSURLMBS class for MBS Xojo Plugins.

1 Like

Use just a few declares. No expensive Plugin is needed.

Public Function VolumeIsBrowsable(Extends target as FolderItem) As Boolean
  Soft Declare Function NSClassFromString Lib "AppKit" (classname As CFStringRef) As ptr
  Soft Declare Function fileURLWithPathIsDirectory Lib "Foundation" Selector "fileURLWithPath:isDirectory:" ( NSURLClass As Ptr, path As CFStringRef, directory As Boolean) As Ptr
  Soft Declare Function getResourceValue Lib "Foundation" Selector "getResourceValue:forKey:error:" ( URLRef As Ptr, ByRef value As Ptr, key As CFStringRef, ByRef error As Ptr ) As Boolean
  Soft Declare Function boolValue Lib "Foundation" Selector "boolValue" ( ref As Ptr ) As Boolean // for converting NSNumber boolean to Xojo
  
  Dim NSURLClass As Ptr = NSClassFromString( "NSURL" )
  Dim nativePath As String = target.nativePath
  Dim myURL      As Ptr = fileURLWithPathIsDirectory( NSURLClass, nativePath, target.directory )
  
  Dim error As ptr
  Dim result As ptr
  If Not GetResourceValue( myURL, result, "NSURLVolumeIsBrowsableKey", error ) Then
    Dim e As New RuntimeException
    e.Message = "An error occurred!"
    Raise e
  End
  
  Return boolValue(result)
  
End Function

a sample in an open Event of a TextArea:

For i As Integer = 0 To FolderItem.LastDriveIndex
  Var f As FolderItem = FolderItem.DriveAt(i)
  Var s As String = f.Name + ": " + If(f.VolumeIsBrowsable, "VISIBLE", "Hidden") + EndOfLine
  Me.AddText(s)
Next
3 Likes

If you have the plugin already, there is no cost :slight_smile:

4 Likes