Page 1 of 1
[Solved] Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
Posted: Mon May 14, 2018 9:50 pm
by trevordevore
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?
Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
Posted: Wed May 16, 2018 6:53 pm
by trevordevore
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.
Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
Posted: Wed Jun 13, 2018 5:15 pm
by trevordevore
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.
Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
Posted: Fri Jun 15, 2018 8:05 am
by LCMark
@trevordevore: I think the problem might be that you have 'returns Boolean' on the foreign binding - rather than 'returns CBool'.
Re: Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]
Posted: Fri Jun 15, 2018 1:20 pm
by trevordevore
@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.