Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
133 lines (104 sloc) 4.15 KB
library com.livecode.extensions.trevordevore.nsrunningapplication
use com.livecode.foreign
use com.livecode.objc
metadata title is "NSRunningApplication"
metadata author is "Trevor DeVore"
metadata version is "0.1.0"
private foreign handler ObjC_NSObjectGetClassName (in pObj as ObjcId) \
returns ObjcId \
binds to "objc:NSObject.-className"
private foreign handler ObjC_NSWorkspaceSharedWorkspace() \
returns ObjcId \
binds to "objc:NSWorkspace.+sharedWorkspace"
private foreign handler ObjC_NSRunningApplicationRunningApplicationWithProcessIdentifier(in pId as CInt) \
returns ObjcId \
binds to "objc:NSRunningApplication.+runningApplicationWithProcessIdentifier:"
private foreign handler ObjC_NSRunningApplicationRunningApplicationsWithBundleIdentifier(in pBundleId as ObjcId) \
returns ObjcId \
binds to "objc:NSRunningApplication.+runningApplicationsWithBundleIdentifier:"
private foreign handler ObjC_NSRunningApplicationActivateWithOptions(in pObj as ObjcId, in pOptions as CInt) \
returns CBool \
binds to "objc:NSRunningApplication.-activateWithOptions:"
/**
Description:
https://developer.apple.com/documentation/appkit/nsapplicationactivationoptions?language=objc
*/
private handler _GetActivationOptions() returns Array
return {"all windows": 1 shifted left by 0 bitwise, \
"ignoring other apps": 1 shifted left by 1 bitwise \
}
end handler
/**
Summary: Returns the list of available activation options.
Description:
See the following url for a description of the options:
https://developer.apple.com/documentation/appkit/nsapplicationactivationoptions?language=objc
* all windows
* ignoring other apps
Returns: Comma-delimited list of options.
*/
public handler NSRunningApplicationActivationOptions() returns String
variable tKeys as List
variable tOptions as String
put the keys of _GetActivationOptions() into tKeys
sort tKeys in ascending text order
combine tKeys with "," into tOptions
return tOptions
end handler
/**
Summary:
Parameters:
pFilename:
Description:
Returns:
*/
public handler NSRunningApplicationActivateWithOptions(in pPid as any, in pOptions as String) returns Boolean
variable runningApp as optional ObjcObject
variable tOptionsLookup as Array
variable tActivationOptions as List
variable tOption as String
variable tOptions as Number
variable wasActivated as Boolean
if pOptions is empty then
put 0 into tOptions
else
put _GetActivationOptions() into tOptionsLookup
split pOptions by "," into tActivationOptions
repeat for each element tOption in tActivationOptions
if tOption is not among the keys of tOptionsLookup then
throw "invalid activation option:" && tOption
end if
put tOptions bitwise or tOptionsLookup[tOption] into tOptions
end repeat
end if
unsafe
if pPid is a number then
put ObjC_NSRunningApplicationRunningApplicationWithProcessIdentifier(pPid) into runningApp
else
variable runningAppArray as ObjcObject
// This returns an array. The first element will have the NSApp object
put ObjC_NSRunningApplicationRunningApplicationsWithBundleIdentifier(StringToNSString(pPid)) into runningAppArray
if runningAppArray is not nothing then
variable tApp as List
put ListFromNSArray(runningAppArray) into tApp
if the number of elements in tApp > 0 then
put element 1 of tApp into runningApp
end if
end if
end if
if runningApp is not nothing then
variable tClassString as ObjcObject
variable tClassName as String
put ObjC_NSObjectGetClassName(runningApp) into tClassString
put StringFromNSString(tClassString) into tClassName
log tClassName
log tOptions
put ObjC_NSRunningApplicationActivateWithOptions(runningApp, tOptions) into wasActivated
end if
end unsafe
if not wasActivated then
log "unable to activate process"
end if
return wasActivated
end handler
end library
You can’t perform that action at this time.