Displaying a file on disk

Here’s the code for the macOS, include it in a module and then call it with folderitem.showInFinder.

[code]Public Sub showInFinder(extends f as folderitem)
#if TargetMacOS then
// — Created for the forum, April the 4th 2020 by Sam Rowlands
declare function NSClassFromString lib “Foundation” ( className as CFStringRef ) as integer
declare function NSMutableArrayWithCapacity lib “AppKit” selector “arrayWithCapacity:” ( NSMutableArrayClass as integer, capacity as integer ) as integer
declare sub NSMutableArrayAddObject lib “AppKit” selector “addObject:” ( NSMutableArray as integer, objectInstance as integer )
declare function NSUrlfileURLWithPathIsDirectory lib “AppKit” selector “fileURLWithPath:isDirectory:” ( NSURLClass as integer, path as CFStringRef, folder as boolean ) as integer
declare function NSWorkspaceSharedWorkspace lib “AppKit” selector “sharedWorkspace” ( NSWorkspaceClass as integer ) as integer
declare sub NSWorkspaceActivateFileViewerSelectingURLs lib “AppKit” selector “activateFileViewerSelectingURLs:” ( shrdWorkSpace as integer, inUrls as integer )

Dim fileArray as integer = NSMutableArrayWithCapacity( NSClassFromString( "NSMutableArray" ), 1 )
NSMutableArrayAddObject( fileArray, NSUrlfileURLWithPathIsDirectory( NSClassFromString( "NSURL" ), f.nativePath, f.directory ) )
NSWorkspaceActivateFileViewerSelectingURLs( NSWorkspaceSharedWorkspace( NSClassFromString( "NSWorkspace" ) ), fileArray )

#endif
End Sub
[/code]