Skip to content

Commit f02e0cf

Browse files
committed
hsmodule: prioritise focused window when searching for Live
1 parent cf00734 commit f02e0cf

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

extensions/les/LESmain.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,14 +1858,21 @@ appwatcher = hs.application.watcher.new(function(name, event, app)
18581858
end):start() -- terminates hotkeys when ableton is unfocussed
18591859
i = 1
18601860
function appwatch(name, event, app)
1861+
-- If something other than Live got caught by the application watcher, just
1862+
-- silently pretend it doesn't exist and hope the next event nets us a Live
1863+
-- instance
1864+
if isHsAppObjLive(app) == false then
1865+
return
1866+
end
1867+
18611868
if hs.window.focusedWindow() == nil then
18621869
goto epicend
18631870
return
18641871
end
18651872

1866-
if event == hs.application.watcher.activated or hs.application.watcher.deactivated then
1873+
if event == hs.application.watcher.activated or event == hs.application.watcher.deactivated then
18671874
if hs.window.focusedWindow() then
1868-
if isHsAppObjLive(hs.window.focusedWindow():application()) then
1875+
if hs.window.focusedWindow():application() == app then
18691876
if threadsenabled == false then
18701877
print("live is in window focus")
18711878
enablemacros()

extensions/les/proccom.lua

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ function isLiveFocused()
3939
return false
4040
end
4141

42-
-- Search for a running instance of Live
43-
--
44-
-- Uses similar fallback to isHsAppObjLive() but doesn't rely on
45-
-- it because APIs are slightly different. Like isHsAppObjLive(),
46-
-- we're relying on exact matching.
47-
function getLiveHsAppObj()
48-
local hsAppObj = hs.application.find(targetBundle)
49-
if hsAppObj == nil then
50-
hsAppObj = hs.application.find(targetName, true, true)
51-
end
52-
return hsAppObj
53-
end
54-
5542
function getLiveVersion(str)
5643
local infoPlistPath = string.format("%s/Contents/Info.plist", str)
5744
if ioIsFilePresent(infoPlistPath) == true then
@@ -83,6 +70,27 @@ function getLiveVersion(str)
8370
, 10)
8471
end
8572

73+
-- Search for a running, preferably in-focus, instance of Live
74+
--
75+
-- Uses similar fallback to isHsAppObjLive() but doesn't rely on
76+
-- it because APIs are slightly different. Like isHsAppObjLive(),
77+
-- we're relying on exact matching.
78+
function getLiveHsAppObj()
79+
local hsAppObj = hs.window.focusedWindow():application()
80+
if isHsAppObjLive(hsAppObj) == false then
81+
hsAppObj = hs.application.find(targetBundle)
82+
end
83+
if hsAppObj == nil then
84+
hsAppObj = hs.application.find(targetName, true, true)
85+
end
86+
if hsAppObj ~= nil then
87+
print(string.format("getLiveHsAppObj(): Found instance of Live %s", getLiveVersion(hsAppObj:path())))
88+
else
89+
print("getLiveHsAppObj(): Unable to find running Live instance")
90+
end
91+
return hsAppObj
92+
end
93+
8694
-- Creates a table of strings consisting of valid Live menu entries
8795
-- (these include children, which findMenuItem may not necessarily
8896
-- include)

0 commit comments

Comments
 (0)