Why use osascript? You can just use a few declares and there is no need for an expensive plugin!
Public Function ExecuteAppleScript(TheScript As String) As String
Soft Declare Function NSClassFromString Lib "AppKit" (classname As CFStringRef) As ptr
Soft Declare Function initWithSource Lib "AppKit" Selector "initWithSource:" (obj As ptr,source As CFStringRef) As ptr
Soft Declare Function executeAndReturnError Lib "AppKit" Selector "executeAndReturnError:" (obj As ptr,ByRef error As ptr) As ptr
Soft Declare Function alloc Lib "AppKit" Selector "alloc" (classRef As Ptr) As Ptr
Soft Declare Function autorelease Lib "AppKit" Selector "autorelease" (classRef As Ptr) As Ptr
Soft Declare Function stringValue Lib "AppKit" Selector "stringValue" (classRef As Ptr) As CFStringRef
Soft Declare Function objectForKey Lib "Foundation" Selector "objectForKey:" (obj_id As ptr, key As CFStringRef) As ptr
Soft Declare Function stringForKey Lib "Foundation" Selector "objectForKey:" (obj_id As ptr, key As CFStringRef) As CFStringRef
Dim nsscript As ptr = autorelease(initWithSource(alloc(NSClassFromString("NSAppleScript")),TheScript))
Dim err As ptr
Dim descriptor As ptr = executeAndReturnError(nsscript,err)
If descriptor = Nil Then
Dim e As New RuntimeException
If err = Nil Then
e.Message = "AppleScript returned an error:" + EndOfLine + "*** Unknown ***"
Else
e.Message = "AppleScript returned an error:" + EndOfLine + stringForKey(err, "NSAppleScriptErrorMessage")
End
Raise e
Else
Return stringValue(descriptor)
End
End Function
and call it via
Dim procName As String = "Xo"
Dim script As String = "tell application ""System Events""" + EndOfLine + _
"set pList To (processes whose name contains """+ procName + """)" + EndOfLine + _
"set pNames To {}" + EndOfLine + _
"repeat With anItem In pList" + EndOfLine + _
"copy (name Of anItem) To the End Of pNames" + EndOfLine + _
"copy {"", ""} To the End Of pNames" + EndOfLine + _
"End repeat" + EndOfLine + _
"set last item Of pNames To {}" + EndOfLine + _
"Return pNames as string" + EndOfLine + _
"End tell" + EndOfLine
Dim result As String = ExecuteAppleScript(script)
in this example I get following result:
Xojo
Note that I modified your AppleScript to get a comma separated list of matching process names.