-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfront_app.lua
More file actions
68 lines (60 loc) · 1.74 KB
/
Copy pathfront_app.lua
File metadata and controls
68 lines (60 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local front_app = SBAR.add('item', 'front_app', {
position = 'left',
display = 'active',
updates = true,
update_freq = 1,
scroll_texts = false, -- Disable text scrolling, just truncate
label = {
color = COLORS.subtext1, -- Softer than primary text, more readable
max_chars = 50, -- Trim long titles (no scrolling)
},
})
local last_window_title = ''
local is_updating = false -- Prevent concurrent updates
-- Optimized function to get and update window title
local function update_window_title()
-- Skip if already updating to prevent concurrent calls
if is_updating then
return
end
is_updating = true
SBAR.exec(
[[
osascript -e 'tell application "System Events"
try
set frontApp to first application process whose frontmost is true
set windowTitle to name of front window of frontApp
return windowTitle
on error
return ""
end try
end tell'
]],
function(result)
is_updating = false
local window_title = ''
if result and result ~= '' then
window_title = result:gsub('\n$', ''):gsub('^%s+', ''):gsub('%s+$', '')
end
-- Only update if title actually changed
if window_title ~= last_window_title then
last_window_title = window_title
-- Direct update without animation for instant response
front_app:set({
label = {
string = window_title,
drawing = window_title ~= '',
},
})
end
end
)
end
-- Update on app switch (primary trigger - instant)
front_app:subscribe('front_app_switched', function(env)
update_window_title()
end)
-- Routine update as fallback (less frequent)
front_app:subscribe('routine', function()
update_window_title()
end)