Help wrapping `[NSRunningApplication runningApplicationWithProcessIdentifier: pid]

Moderators: LCMark, LCfraser

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

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?
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: 865
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

Post Reply

Return to “LiveCode Builder”