Help with AppleEvent please

  1. 2 months ago

    Lennox J

    Jan 9 Jamaica. West Indies
    Edited 2 months ago

    Hello,

    Using macOS Mojave Version 10.14.2 on Mac mini (Late 2014), 3 GHz Intel Core i7, 16 GB 1600 MHz DDR3 with Xojo Version 2018 Release 4
    I have read this... https://nug.xojo.narkive.com/5iB1iodb/show-me-in-the-finder

    and I have tried the following...

    dim ae As AppleEvent
    ae=newAppleEvent("misc", "slct", "MACS")
    ae.folderitemparam("----") = app.gf
    
    if not ae.send then
    MsgBox "Finder not running."
    
    else
    ae = newAppleEvent("misc", "actv", "MACS")   // the folderitem is not highlighted in its parent folder
    'ae=newAppleEvent("misc", "mvis", "MACS")   // the folderitem is not highlighted in its parent folder
    
    if not ae.send then
    MsgBox "Finder not running."
    else
    'MsgBox "Finder is running."   // if this is uncommented the msgbox is displayed indicating "Finder is running."
    ae.folderitemparam("----") = app.gf
    'MsgBox app.gf.name   // if this is uncommented the msgbox is displayed indicating the correct app.gf.name
    end if
    
    'app.gf.Parent.launch   // if this is uncommented the correct app.gf.Parent is launched
    end if

    Any help/suggestions as to why the folderitem is not highlighted in its parent folder?

    Thanks.

    Lennox

    @Lennox J — OK, this works in Sierra and should also work in Mojave:

    const cocoa = "Cocoa.framework"
      
      declare function NSClassFromString lib cocoa (name as CFStringRef) as Ptr
      declare function sharedWorkspace lib cocoa selector "sharedWorkspace" (id as Ptr) as Ptr
      declare function selectFile lib Cocoa selector "selectFile:inFileViewerRootedAtPath:" (id as Ptr, fullPath as CFStringRef, rootedAtPath as CFStringRef) as Boolean
      
      dim ws as Ptr = NSClassFromString( "NSWorkspace" )
      dim sws as Ptr = sharedWorkspace( ws )
      
      dim path as String = "/full/path/to/file"
      
      if NOT selectFile( sws, path, path ) then
        beep //Error
      end if
  2. Dave S

    Jan 9 San Diego, California USA
    Edited 2 months ago

    Didn't I read somewhere that AppleEvent processing was now restricted in someway with Mojave for "Security" reasons?

    That link you posted is over 9 years old

    https://docs.xojo.com/AppleEvent

    In order to use AppleEvents on newer versions of macOS (Mojave and later) you will need to include the NSAppleEventsUsageDescription key in your plist file.

    10 seconds of research goes a long way

  3. Lennox J

    Jan 9 Jamaica. West Indies

    Thanks Dave, wasn't aware that AppleEvent processing is now restricted in someway with Mojave for "Security" reasons.

    So, is there another way to show a folderitems in the finder?

    Thanks again.

    Lennox

  4. Dave S

    Jan 9 San Diego, California USA
    Edited 2 months ago

    updated my response

  5. Lennox J

    Jan 9 Jamaica. West Indies

    Hi Dave,

    I don't know what is meant by "updated by response", kindly explain.

    Thanks.

    Lennox

  6. @Lennox J — Yes, you can use declares. It is not complicated but long. Just give me some time

  7. Dave S

    Jan 9 San Diego, California USA

    @Lennox J Hi Dave,

    I don't know what is meant by "updated by response", kindly explain.

    Thanks.

    Lennox

    I mean I added more to my response since you read it.... including a possible solution

  8. Stéphane M

    Jan 9 Answer France

    @Lennox J — OK, this works in Sierra and should also work in Mojave:

    const cocoa = "Cocoa.framework"
      
      declare function NSClassFromString lib cocoa (name as CFStringRef) as Ptr
      declare function sharedWorkspace lib cocoa selector "sharedWorkspace" (id as Ptr) as Ptr
      declare function selectFile lib Cocoa selector "selectFile:inFileViewerRootedAtPath:" (id as Ptr, fullPath as CFStringRef, rootedAtPath as CFStringRef) as Boolean
      
      dim ws as Ptr = NSClassFromString( "NSWorkspace" )
      dim sws as Ptr = sharedWorkspace( ws )
      
      dim path as String = "/full/path/to/file"
      
      if NOT selectFile( sws, path, path ) then
        beep //Error
      end if
  9. Lennox J

    Jan 9 Jamaica. West Indies

    Thanks Stéphane Mons, works well.

    Will try Dave's suggestion/method later.

    Thanks again Stéphane & Dave.

    Lennox

or Sign Up to reply!