Show In Finder

I found this code somewhere on this forum a few years ago. and it seems to work just fine

Public Sub Show_in_Finder(f as FolderItem)
Dim a As AppleEvent = New AppleEvent("misc", "slct", "com.apple.finder")
  a.FolderItemParam("----") = f
  If a.send Then
    a = New AppleEvent("misc", "actv", "com.apple.finder")
    If a.send Then
    End If
  End If
  
End Sub

But am I correct that this is NOT acceptable to the AppStore?

Also I need a similar routine to implement the QuickLook function (assuming it is not code inside Xcode which is where I saw it)

QuickLook can be called via Shell

Public Sub QuickLook(f as FolderItem)
Dim sh As New shell
 sh.Execute "qlmanage -p "+chrb(34)+f.NativePath+chr(34)+" > /dev/null"
End Sub

Just tried the command line myself, it launched a process which I kind of thought would happen, but what I didn’t expect was a new icon to appear in the dock. The /dev/null isn’t necessary at all it seems.

I can’t ever recall off the top of my head what the official stance is from Apple on using Shell in the app store, but this doesn’t seem like a very smooth solution because of the extra dock icon. QuickLook previews in other apps just open a quick look window (using Transmit 5 as an example).

According the the site where I found the QuickLook command, it said to add the Dev/Null to reduce the overhead of what is otherwise a long stream of “process data” that isn’t necessary

And it did say the Qlmanage “is not the same as the Quicklook in various Apple Programs”

So if you or anyone else has a better solution, I’m all ears :)…

And the Appstore question was aimed more at APPLEEVENT than at SHELL

nohup still shows the dock icon

You are correct.
Apple Script is permitted, but not for Finder, System Events, System Preferences or Terminal. It is also not permitted if it doesn’t use the newer “Scripting Targets”. Basically Apple Script is dead if you want to sell on the Mac App Store. And yes its the same for Apple Events also.

Instead use NSWorkspace declares or Plugins.

IIRC this is for debugging QuickLook plugins.[quote=371911:@Dave S]So if you or anyone else has a better solution, I’m all ears :)…[/quote]
Use the Quicklook Preview Panel within your application.
https://developer.apple.com/documentation/quartz/qlpreviewpanel?language=objc

Not worth the effort… a window and a canvas will do what I need…
I was hoping to do it with a few lines of “declare” but seems that not an option

Sadly implementing QuickLook is not as simple as it should be, there is a cheat API for making the system generate a preview, but it’s also different than what you would actually see if you used the proper QuickLook Preview Panel.

Maybe NSWorkspace->activateFileViewerSelecting would work.

No clue what that means

Show In Finder

People using my plugins, can use NSWorkspaceMBS class and the activateFileViewerSelectingURLs or activateFileViewerSelectingFiles functions there.

If you prefer declares, start reading here: NSWorkspace

Gee… If I were writing this in SWIFT perhaps those documents would be of some help

Or you could just grab the macosLib. “activateFileViewerSelecting” is implemented there…
(I did not test it myself).

  declare function objc_getClass lib "libobjc.dylib" ( name as CString ) as ptr
  Declare Function sharedWorkspace Lib "AppKit" selector "sharedWorkspace" ( obj As ptr ) As ptr
  declare function selectFile lib "AppKit" selector "selectFile:inFileViewerRootedAtPath:" ( obj as ptr, fPath as CFStringRef, rootFullPath as CFStringRef ) as boolean
  dim workspace as ptr = sharedWorkspace( objc_getClass( "NSWorkspace" ) )
  call selectFile( workspace, f.NativePath, "")

Jason… doesn’t compile

  • Assert - item does not exist
  • FolderItem has not member named PosixPath

but this does… and it seems not to violate any AppStore rules

Dim sh As New shell
sh.Execute "open -R "+chrb(34)+f.NativePath+chr(34)

This does work.

A small correction though:
The assert line must removed and use “f.NativePath” instead of “f.PosixPath”.

[quote=372005:@Thomas Eckert]This does work.
A small correction though:
The assert line must removed and use “f.NativePath” instead of “f.PosixPath”.[/quote]

Thanks… I knew that “posixpath” HAD existed … but the LR says that SHELLPATH should have been the replacement

working code

Declare Function objc_getClass Lib "libobjc.dylib" ( name As CString ) As ptr
Declare Function sharedWorkspace Lib "AppKit" selector "sharedWorkspace" ( obj As ptr ) As ptr
Declare Function selectFile Lib "AppKit" selector "selectFile:inFileViewerRootedAtPath:" ( obj As ptr, fPath As CFStringRef, rootFullPath As CFStringRef ) As Boolean
Dim workspace As ptr = sharedWorkspace( objc_getClass( "NSWorkspace" ) )
// assert ( workspace <> nil, CurrentMethodName + " is Nil")
Call selectFile( workspace, f.Nativepath, "")

Update for app hardening!
If you sign your app with runtime hardening enabled, accessing libobjc.dylib directly will raise an exception! Swap out “libobjc.dylib” for “Cocoa” in the declare above to keep working with Mojave!

Shell is perfectly OK with the MAS. I have several apps that rely on shell there.

But I got to ask, what are you exactly trying to do, Dave ?