For starters, awesome project! Feel like a kid in a candy store with no adults around!
I wanted to check with you about an issue I found with Github's Atom editor where the launchOrFocus function does not seem to detect the running application. It always launches a new one.
Something simple like this should produce it:
hs.hotkey.bind(hyper, "a", function() hs.application.launchOrFocus("Atom") end)
I guess it must be something odd with Atom itself, because the code works fine for all the other applications I've tried...
Incidentally, I discovered your toggle_application function which works fine with Atom (more awesomeness that I switched my key bindings to now anyway!)
Cheers!
I actually have the same issue with iterm2
hs.hotkey.bind(hyper, '1', function () hs.application.launchOrFocus("iTerm2") end)
spawns another instance of iTerm2.
What version of iTerm2 are you running? I think they dropped a "2" from the app name several months ago.
Mine works fine, but I use:
hs.hotkey.bind(hyper, 'f', function() hs.application.launchOrFocus("iTerm") end)
I'm pretty sure it's called iTerm2.
_Update_: the stable version is called iTerm, but if you build from source or use a nightly build it's called iterm2.
Is there another identifier I should be aware of?
I test out two cases (in both cases no instance of iterm2 is running):
if I then switch applications and open/focus iterm2 with the keybinding
in case 1) a new instance opens
in case 2) iterm2 will be focused
@phiche this is very likely because Atom reports itself as a different name to the OS than its application bundle. You can work around this by figuring out what those names are (inspecting hs.application.runningApplications() with hs.inspect, should help there) and then writing a little function that checks for the presence of a running Atom instance and either focuses it or launches a new instance if it's not running.
I'm not sure if this is something we should be handling - it would be nice to have things magically work, but I'm not sure if this is something we can easily detect and workaround (without maintaining an awful whitelist of applications that do this)
It might be worth putting together a module of utilities like you suggest that help in tracking down/working around oddities... fodder for another thread to suggest what types of tools would be helpful?
On May 13, 2015, at 1:49 PM, Chris Jones [email protected] wrote:
@phiche https://github.com/phiche this is very likely because Atom reports itself as a different name to the OS than its application bundle. You can work around this by figuring out what those names are (inspecting hs.application.runningApplications() with hs.inspect, should help there) and then writing a little function that checks for the presence of a running Atom instance and either focuses it or launches a new instance if it's not running.
I'm not sure if this is something we should be handling - it would be nice to have things magically work, but I'm not sure if this is something we can easily detect and workaround (without maintaining an awful whitelist of applications that do this)
—
Reply to this email directly or view it on GitHub https://github.com/Hammerspoon/hammerspoon/issues/288#issuecomment-101774081.
@asmagil sounds sane :)
@asmagill great idea!
thanks @cmsj!
Did anyone get around this? I'm using Atom, but considering to go back to SublimeText because of this.
I ran into this issue suddenly (on OSX El Capitan), and it turns out there were some weird Atom processes running which didn't have any windows, which caused hs.application.find to pick up the wrong Atom instance. I fixed it by running ps aux | grep Atom and killing all Atom PIDs with kill -9.
I've had this problem before, and recently my Atom stopped opening entirely from hammerspoon commands. I'm posting this on the off chance it might help even one person, this fixed my Atom issue entirely- it no longer opens extra instances and it properly opens and focues. Instead of "Atom" I included the whole path:
hs.application.launchOrFocus("/Applications/Atom.app")
Note: I am running OSX El Capitan 10.11.6.