AS to ASOBJC - System Events

Hi guys,

I am translating an older app that I did with AS to ASOBJC…
The part I am fighting with is the following:


tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)

So I look around and tested quite some things but never really got it to work.
I thought I would get the same result when I get all running processes and seach for a particular name (appname).


set allApps to current application's NSWorkspace's sharedWorkspace()'s runningApplications()
set queryString to "Calendar" as text
set myResult to allApps's stringByReplacingOccurrencesOfString_withString_("RUNNING", queryString)

With this I get

Ok, so I cannot use the stringsearch with an array but how can I translate that?
Or is there a better way of tranlating the above AS?

Cheers,
Chris

This:
current application’s NSWorkspace’s sharedWorkspace()'s runningApplications()
is returning an NSArray.

This:
stringByReplacingOccurrencesOfString_withString_(“RUNNING”, queryString)
works on strings, not arrays.

So you have to repeat/iterate on each item of the “allApps”. Or, you can combine all the items of the array into one big string first then do the replacement.

so something like:

set newArray to {} as list
repeat with anItem in allApps
set myResult to anItem's stringByReplacingOccurrencesOfString_withString_("RUNNING", queryString)
copy myResult to end of newArray
end repeat

Hi,

the ASOC equivalent of

tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)

is


set bundleIdentifierQuery to "com.apple.iCal"
set runningApplications to current application's NSWorkspace's sharedWorkspace()'s runningApplications()
set predicate to current application's NSPredicate's predicateWithFormat_("bundleIdentifier like %@", bundleIdentifierQuery)
set appNameIsRunning to (runningApplications's filteredArrayUsingPredicate_(predicate)'s |count|() > 0) as boolean

Thanks guys! Tried both ways and got them to work.
Perfect.