Show In Finder

  1. 2 years ago

    Dave S

    1 Feb 2018 San Diego, California USA

    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)

      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, "")
  2. Dave S

    1 Feb 2018 San Diego, California USA

    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
  3. Tim P

    1 Feb 2018 Pre-Release Testers Rochester, NY
    Edited 2 years ago

    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).

  4. Dave S

    1 Feb 2018 San Diego, California USA

    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

  5. Dave S

    1 Feb 2018 San Diego, California USA

    nohup still shows the dock icon

  6. Sam R

    1 Feb 2018 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

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

    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.

    @Dave S QuickLook can be called via Shell

    IIRC this is for debugging QuickLook plugins.

    @Dave S So if you or anyone else has a better solution, I'm all ears :)....

    Use the Quicklook Preview Panel within your application.
    https://developer.apple.com/documentation/quartz/qlpreviewpanel?language=objc

  7. Dave S

    1 Feb 2018 San Diego, California USA

    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

  8. Sam R

    1 Feb 2018 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    @Dave S 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.

  9. Jason P

    1 Feb 2018 Xojo Inc Texas

    Maybe NSWorkspace->activateFileViewerSelecting would work.

  10. Dave S

    1 Feb 2018 San Diego, California USA

    @Jason P Maybe NSWorkspace->activateFileViewerSelecting would work.

    No clue what that means

  11. Sam R

    1 Feb 2018 Pre-Release Testers, Xojo Pro, Third Party Store Hengchun, Pingtung, Taiwan

    @Dave S No clue what that means

    Show In Finder

  12. Christian S

    2 Feb 2018 Pre-Release Testers, Xojo Pro, XDC Speakers, Third Party Store Germany

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

    If you prefer declares, start reading here: NSWorkspace

  13. Dave S

    2 Feb 2018 San Diego, California USA

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

  14. Thomas E

    2 Feb 2018 Pre-Release Testers

    @Dave S 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).

  15. Jason P

    2 Feb 2018 Xojo Inc Answer Texas
    Edited 2 years ago
      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, "")
  16. Dave S

    2 Feb 2018 San Diego, California USA

    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)
  17. Thomas E

    2 Feb 2018 Pre-Release Testers

    This does work.

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

  18. Dave S

    2 Feb 2018 San Diego, California USA

    @Thomas E This does work.
    A small correction though:
    The assert line must removed and use "f.NativePath" instead of "f.PosixPath".

    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, "")
  19. 3 weeks ago

    Tim P

    Oct 28 Pre-Release Testers Rochester, NY

    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!

  20. Newer ›

or Sign Up to reply!