-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailMateFocus.lua
63 lines (54 loc) · 2.31 KB
/
MailMateFocus.lua
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
---
--- Generated by Luanalysis
--- Created by muescha.
--- DateTime: 28.01.23 23:50
---
local scriptInfo = fileInfo()
-- Define a variable to store the MailMate bundle ID
local mailmateBundleID = "com.freron.MailMate"
-- Define a variable to store the Chrome bundle ID
local chromeBundleID = "com.google.Chrome"
-- Define a function to check if the current app is MailMate and the cmd key was pressed while clicking a link
local function checkCmdClickInMailmateAndActivateMailmate()
-- Setup the click behaviour:
-- -> use normal click to come back: false
-- -> use cmd+click to come back: true
local enable_cmdClick = false
if hs.application.frontmostApplication():bundleID() ~= mailmateBundleID then
--debugInfo(scriptInfo, 'not in MailMate --> exit')
return false
end
if enable_cmdClick then
if not hs.eventtap.checkKeyboardModifiers()['cmd'] then
debugInfo(scriptInfo, 'no modifier `cmd` --> exit')
return false
end
else
local mousePos = hs.mouse.absolutePosition()
--debugInfo(scriptInfo,'mousePos ',mousePos)
local focusedWindow = hs.window.focusedWindow()
--debugInfo(scriptInfo,'focusedWindow ',focusedWindow)
local frame = focusedWindow:frame()
--debugInfo(scriptInfo,'frame ',frame)
if mousePos.x < frame.x or mousePos.y < frame.y or
mousePos.x > frame.x + frame.w or mousePos.y > frame.y + frame.h then
-- Click occurred outside the window
debugInfo(scriptInfo, "Click outside MailMate window --> exit")
return false
else
-- Click occurred inside the MailMate window
--debugInfo(scriptInfo, "Click inside MailMate window")
end
end
hs.timer.doAfter(0.5, function()
if hs.application.frontmostApplication():bundleID() == chromeBundleID then
debugInfo(scriptInfo, 'we are now in Chrome --> switch back')
hs.application.get(mailmateBundleID):activate()
else
debugInfo(scriptInfo, 'no app change --> exit')
end
end)
return false
end
-- it need to be a global variable so this is not garbage collected
MailMateFocus_EventTap = hs.eventtap.new({hs.eventtap.event.types.leftMouseDown}, checkCmdClickInMailmateAndActivateMailmate):start()