-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexportImage.lua
More file actions
50 lines (39 loc) · 1.59 KB
/
exportImage.lua
File metadata and controls
50 lines (39 loc) · 1.59 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
function printf(s,...) print(s:format(...)) end
function fastExportImage()
-- whether the pohtoshop is in focus
local window = hs.window.focusedWindow()
local app = window:application()
local title = app:title()
local isPhotoshop = title:find("Photoshop CC")
if( not isPhotoshop ) then
printf('invoke on %s, skip', title)
return
end
-- click the menu item
local str_export = {"File", "Export", "Quick Export as PNG"}
app:selectMenuItem(str_export)
-- whether the SAVE AS modal dialog has been presented
local predicateFn = function()
local window = app:focusedWindow()
local isSaveAs = window:title():find("Save As")
if( not isSaveAs ) then
printf("keep waiting, current window: %s", title)
end
return isSaveAs
end
-- add prefix to file name, and save
local actionFn = function()
printf("action")
hs.eventtap.event.newKeyEvent("left", true):post()
hs.eventtap.event.newKeyEvent("left", false):post()
-- break shirt + - into 4 event
hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, true):post()
hs.eventtap.event.newKeyEvent("-", true):post()
hs.eventtap.event.newKeyEvent("-", false):post()
hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, false):post()
hs.eventtap.event.newKeyEvent("return", true):post()
hs.notify.new({title="Hammerspoon", informativeText="Operation complete"}):send()
end
hs.timer.waitUntil(predicateFn, actionFn, 0.2)
end
hs.hotkey.bind({ "alt" }, 'E', fastExportImage)