-
Notifications
You must be signed in to change notification settings - Fork 71
/
grammarly.fnl
35 lines (32 loc) · 1.26 KB
/
grammarly.fnl
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
;; somehow Grammarly doesn't let you easily copy or cut the text out of its
;; window. so I need to emulate a click event first.
(fn click-in-window []
(let [app (-> (hs.window.focusedWindow) (: :application))
win (: app :mainWindow)
frame (: win :frame)
{:_x x :_y y} frame
coords {:x (+ x 100) :y (+ y 100)}]
(: (hs.eventtap.event.newMouseEvent
hs.eventtap.event.types.leftMouseDown
coords) :post)
(: (hs.eventtap.event.newMouseEvent
hs.eventtap.event.types.leftMouseUp
coords) :post)))
(fn back-to-emacs
[]
(let [windows (require :windows)
run-str (.. "/usr/local/bin/emacsclient"
" -e "
"'(with-current-buffer (window-buffer (selected-window)) "
" (if (region-active-p)"
" (delete-region (region-beginning) (region-end))"
" (erase-buffer))"
" (clipboard-yank))" "'")
app (-> (hs.window.focusedWindow) (: :application))]
(click-in-window)
(: app :selectMenuItem [:Edit "Select All"])
(: app :selectMenuItem [:Edit :Cut])
(hs.timer.usleep 200000)
(io.popen run-str)
(hs.application.launchOrFocus :Emacs)))
{:back-to-emacs back-to-emacs}