Help with AppleEvent please

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

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://documentation.xojo.com/api/language/app.htmlleEvent

10 seconds of research goes a long way

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

updated my response

Hi Dave,

I don’t know what is meant by “updated by response”, kindly explain.

Thanks.

Lennox

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

[quote=420731:@Lennox Jacob]Hi Dave,

I don’t know what is meant by “updated by response”, kindly explain.

Thanks.

Lennox[/quote]
I mean I added more to my response since you read it… including a possible solution

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

[code]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[/code]

Thanks Stphane Mons, works well.

Will try Dave’s suggestion/method later.

Thanks again Stphane & Dave.

Lennox