Closed lowne closed 9 years ago
this could just be a simple wrapper around a search of hs.application.runningApplications()
I had assumed there would be a more direct way to do this with the c object (check if the PID still exists) - if that's not the case then sure, I'll do it Lua side.
@lowne I think that's going to be safest. AFAICS there isn't a decent API for checking if a specific app is running, so we'd be doing the same thing in C.
Couldn't this be a simple wrapper around hs.application.get()
? I've been using this in my config and seems to work fine (see for example https://github.com/zzamboni/hammerspoon/blob/f291e402205b48f72f06fc96f2a151de84ad334b/extensions/spotify/init.lua#L179)
(apologies for the completely misguided comment - I also didn't get you were asking for an instance method and not a class method - my reading of Lua syntax nuances is still weak).
@cmsj from the docs:
runningApplicationWithProcessIdentifier: Returns the running application with the given process identifier, or nil if no application has that pid.
so it seems it'd just be a check for nsobject_for_app(...)==nil
(see :bundleID()
in internal.m
)
(EDIT: I'm aware of the ridiculousness of not just doing it myself, but my Xcode allergy is getting worse)
oh, hrm, for some reason I thought you wanted to go from an application name to its running status, but you very clearly asked for an hs.application
object method. My bad :)
In that case, yes, that function should work fine
Yes, in hindsight OP wasn't worded very clearly, sorry. In case you missed the edit above: I'm aware of the ridiculousness of not just doing it myself, but my Xcode allergy is getting worse. :)
... for possibly outdated references. For now I'm checking
:bundleID()
as it apparently returnsnil
for dead processes, but idk if that's guaranteed to work (and it's inelegant)