[Solved] Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Moderators: LCMark, LCfraser

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 911
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

[Solved] Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Post by trevordevore » Mon May 14, 2018 9:50 pm

I'm struggling to wrap `[NSRunningApplication runningApplicationWithProcessIdentifier: t_psn]. Here are the docs:

https://developer.apple.com/documentati ... guage=objc

You can find the full source code that will compile in LC 9 here:

https://github.com/trevordevore/lc-maco ... cation.lcb

I'm trying to call `NSRunningApplicationActivateWithOptions()` as follows (2203 is a PID taken from Activity Monitor so adjust accordingly):

Code: Select all

put NSRunningApplicationActivateWithOptions(2203, "ignoring other apps")
The problem is that line 83 always returns nil:

Code: Select all

put ObjC_NSRunningApplicationRunningApplicationWithProcessIdentifier(runningApp, pPid) into runningApp
This seems like a pretty straightforward API call and I have a number of other NS* code working. I'm wondering if something is wrong with the way the pId Integer parameter is being passed to the FFI handler?

Any ideas?
Last edited by trevordevore on Fri Jun 15, 2018 2:33 pm, edited 2 times in total.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 911
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Post by trevordevore » Wed May 16, 2018 6:53 pm

I've determined that you don't need to pass an ObjcId to runningApplicationWithProcessIdentifier as it is a class property. The following code returns a valid reference to a running application:

Code: Select all

private foreign handler ObjC_NSRunningApplicationRunningApplicationWithProcessIdentifier(in pId as CInt) returns ObjcId binds to "objc:NSRunningApplication.+runningApplicationWithProcessIdentifier:"
Now I'm getting a crash elsewhere in the code so I'm working on that.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 911
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Post by trevordevore » Wed Jun 13, 2018 5:15 pm

I've been unable to figure out what is causing the crash when calling [NSRunningApplication -activateWithOptions:].

I've confirmed that I am getting an object with class NSRunningApplication by extracting the object returned in an array by [NSRunningApplication +runningApplicationsWithBundleIdentifier:]. I'm currently passing in 0 for the options but passing in acceptable flags still cause crashes.

I wondered if perhaps I needed to use ObjcRetainedId for any object types so I've tried changing those. If that is the cause I haven't found the correct configuration yet.

The code is still available here:

https://github.com/trevordevore/lc-maco ... cation.lcb

You can create the crash by calling the following from the message box after running the code using the Extension Builder:

Code: Select all

get NSRunningApplicationActivateWithOptions("com.runrev.livecode", "")
Any help on this would be greatly appreciated. I'm hoping I don't have to set up my machine to compile the LiveCode IDE in order to debug the engine in order to figure this out.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 996
Joined: Thu Apr 11, 2013 11:27 am

Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Post by LCMark » Fri Jun 15, 2018 8:05 am

@trevordevore: I think the problem might be that you have 'returns Boolean' on the foreign binding - rather than 'returns CBool'.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 911
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Post by trevordevore » Fri Jun 15, 2018 1:20 pm

@LCMark - Thanks, that fixed it! I had a similar problem with a handler I wrote early on in my experiments. I had defined a parameter in a foreign handler as Integer instead of CUInt. Nothing crashed but the handler didn't work. Once I noticed the problem everything magically fell into place.
Trevor DeVore
ScreenSteps - http://www.screensteps.com

Levure Application Framework: https://github.com/trevordevore/levure
LiveCode Resources for Developers: http://livecode.bluemangolearning.com

Post Reply

Return to “LiveCode Builder”