Thomas Tempelmann had the best idea: fix the declare from Jürg to find the correct folder:
[code]#If TargetMacOS Then
//https://developer.apple.com/documentation/foundation/nsfilemanager/1407726-urlsfordirectory?language=objc
//- (NSArray<NSURL *> *)URLsForDirectory:(NSSearchPathDirectory)directory inDomains:(NSSearchPathDomainMask)domainMask;
Declare Function NSClassFromString Lib “Foundation” (className As CFStringRef) As Ptr
Declare Function defaultManager Lib “Foundation” selector “defaultManager” (ptrNSFileManagerClass As Ptr) As Ptr
Declare Function path Lib “Foundation” selector “path” (ptrNSURLInstance As Ptr) As CFStringRef
Declare Function fileExistsAtPathAndIsDirectory Lib “Foundation” selector “fileExistsAtPath:isDirectory:” (ptrNSFileManagerInstance As Ptr, path As CFStringRef, ByRef isDirectory As Boolean) As Boolean
Dim ptrNSFileManagerClass As Ptr = NSClassFromString(“NSFileManager”)
if (ptrNSFileManagerClass = nil) then return nil
Dim ptrToNSFileManagerDefaultInstance As Ptr = defaultManager(ptrNSFileManagerClass)
if (ptrToNSFileManagerDefaultInstance = nil) then return nil
Declare Function URLsForDirectory Lib “Foundation” selector “URLsForDirectory:inDomains:” (ptrToNSFileManagerInstance As Ptr, NSSearchPathDirectory As UInteger, NSSearchPathDomainMask As UInteger) As Ptr
const kNSAllApplicationsDirectory = 100
const kNSApplicationDirectory = 1
const kNSAllDomainsMask = &h0ffff
const kNSLocalDomainMask = 2
Declare Function NSArrayCount Lib “Foundation” selector “count” (ptrToNSArray As Ptr) As UInteger
Declare Function NSArrayObjectAtIndex Lib “Foundation” selector “objectAtIndex:” (ptrToNSArray As Ptr, index As UInteger) As Ptr
Declare Function NSArrayObjectAtIndex_IsA_CFStringRef Lib “Foundation” selector “objectAtIndex:” (ptrToNSArray As Ptr, index As UInteger) As CFStringRef
Declare Function CFURLCopyFileSystemPath Lib “Foundation” (anURL As Ptr, pathStyle As Int32) As CFStringRef
Const kCFURLPOSIXPathStyle = 0
Const kCFURLHFSPathStyle = 1
Dim ptrToArray As Ptr = URLsForDirectory(ptrToNSFileManagerDefaultInstance, kNSApplicationDirectory, kNSLocalDomainMask)
If (ptrToArray = Nil) Then Return Nil
Dim iResultCount As UInteger = NSArrayCount(ptrToArray)
If (iResultCount < 1) Then Return Nil
Dim oResults() As FolderItem
For i As Integer = 0 To iResultCount - 1
Dim ptrToNSURL As Ptr = NSArrayObjectAtIndex(ptrToArray, i)
If (ptrToNSURL = Nil) Then Continue
Dim bIsDirectory As Boolean = false
if (not fileExistsAtPathAndIsDirectory(ptrToNSFileManagerDefaultInstance, path(ptrToNSURL), bIsDirectory)) or (not bIsDirectory) then continue
Dim sNativePath As String = CFURLCopyFileSystemPath(ptrToNSURL, kCFURLPOSIXPathStyle)
Try
Dim oResult As New FolderItem(sNativePath, FolderItem.PathTypeNative)
oResults.Append(oResult)
Catch UnsupportedFormatException
'ignore
End Try
Next
If (oResults.Ubound >= 0) Then Return oResults
Return Nil
#EndIf
Return Nil
[/code]