-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.lua
300 lines (231 loc) · 8.56 KB
/
init.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
local ZBS = "/Applications/ZeroBraneStudio.app/Contents/ZeroBraneStudio"
package.path = package.path .. ";" .. ZBS .. "/lualibs/?/?.lua"
package.path = package.path .. ";" .. ZBS .. "/lualibs/?.lua"
package.cpath = package.cpath .. ";" .. ZBS .. "/bin/?.dylib"
package.cpath = package.cpath .. ";" .. ZBS .. "/bin/clibs53/?.dylib"
--require("mobdebug").start()
print("package.path:" .. package.path)
print("package.cpath:" .. package.cpath)
hammerspoon_data_dir = hs.fs.pathToAbsolute("~/hammerspoon-data")
require("utils")
--*******************************
require("papyrus-functions")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, '1', "toggle_papyrus", toggle_papyrus_bereich)
myPathWatcher= hs.pathwatcher.new(os.getenv("HOME") .. "/Documents/papyrus/numnum/belege/Autoreports/", renameBeleg):start()
hotkey_cmd_minus = hs.hotkey.bind({"cmd"}, "-", "zoomOut", zoomOut)
hotkey_cmd_plus = hs.hotkey.bind({"cmd"}, "+", "zoomIn", zoomIn)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "delete", "deleteObject",deleteObject)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "8", "makeGroupFromBox", makeGroupFromBox)
--*******************************
require("clipboard-functions")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "6", "iterateWords", iterateWords)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "7", "parseSimpleMindFile", parseSimpleMindFile)
--hs.hotkey.bind({"ctrl", "alt", "cmd"}, "2", function() hs.eventtap.keyStrokes(hs.pasteboard.getContents()) end)
-- delete from line 43 - 1195
function process_file(pathname)
local tmp_pathname = string.gsub(pathname, ".txt", ".old-txt", 1)
print(tmp_pathname)
os.rename(pathname, tmp_pathname)
local file = io.open (pathname, "a")
local line_nr = 1
for line in io.lines(tmp_pathname) do
local parts = split(line, "[^:]*")
local rank = tonumber(parts[3])
if line_nr < 44 or line_nr > 1195 then
file:write(line .. "\n")
print(line_nr .. ":" .. line)
end
line_nr = line_nr + 1
end
file:close()
end
function fillSelectedFileContentsIntoClipboard()
local pathlist = hs.dialog.chooseFileOrFolder("Wähle eine Datei aus. Ihr Inhalt wird ins Clipboard kopiert.", hammerspoon_data_dir, true, false, false)
print("path:" .. pathlist["1"])
local content = read_file(pathlist["1"])
print(content)
hs.pasteboard.setContents(content)
end
function processSelectedFiles()
local pathlist = hs.dialog.chooseFileOrFolder("Wähle Dateien aus, die bearbeitet werden sollen.", hammerspoon_data_dir, true, false, true)
for ix,pathname in pairs(pathlist) do
print(ix .. "path:" .. pathname)
process_file(pathname)
end
end
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "f", "processSelectedFiles", processSelectedFiles)
--*******************************
require("webview-functions")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "i", "printInBrowser", function() printInBrowser("immer noch alles klar mit der anzeige von textinformationen") end)
--*******************************
require("polling")
require("bitcoin-mining")
--hs.hotkey.bind({"ctrl", "alt", "cmd"}, "m", "miningStatistic", miningStatistic)
--*******************************
require("amazon_salesrank")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "a", "amazon_salesrank", amazon_salesrank)
function restart_timers()
for ix,timer in ipairs(timer_table) do
-- timer:fire()
if timer:running() then
print( ("timer %d: next trigger in %.1f Stunden"):format(ix, timer:nextTrigger()/3600) )
else
print("timer is not running")
-- timer:start()
end
end
end
function test_function()
-- local timestamp = os.date("%Y-%m-%dT%H:%M:%SZ")
-- global_timestamp = timestamp
-- hs.alert.show("test_function:" .. timestamp)
-- write_log("doAt-test", timestamp)
hs.eventtap.keyStroke({"cmd"}, 'C')
local allURLs = hs.pasteboard.readURL(nil, true)
-- local content = hs.pasteboard.getContents()
local entries = #allURLs
print("test_function(): entries=" .. entries)
local point = hs.mouse.getRelativePosition()
hs.eventtap.rightClick(point)
hs.timer.doAfter(0.5, function()
hs.eventtap.keyStroke({}, 'right')
hs.eventtap.keyStroke({}, 'down')
hs.eventtap.keyStroke({}, 'down')
if entries > 1 then
hs.eventtap.keyStroke({}, 'down')
end
hs.eventtap.keyStroke({}, 'return')
end )
return 0
end
--*******************************
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "x", test_function)
--*******************************
require("applescript-functions")
--*******************************
require("menubar-examples")
--function noise_recognized(which)
-- hs.alert.show("noise!:")
--end
--noise_listener = hs.noises.new(noise_recognized):start()
speaker = hs.speech.new()
function get_user_input()
local button, text_input = hs.dialog.textPrompt("Test der Sprachausgabe", "Gib ein Wort ein", "mach schon!", "OK", "Abbrechen")
if button == "OK" then
speaker:speak(text_input)
end
end
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "s", "Sprachausgabe", get_user_input)
--*******************************
require("http-functions")
--*********************************
-- S P O O N S
-- you need to remove the comments for all installed Spoons
--*********************************
--[[hs.loadSpoon("ClipboardTool")
--print(spoon.ClipboardTool.name)
--print(spoon.ClipboardTool.homePage)
spoon.ClipboardTool.show_in_menubar = true
--print(spoon.ClipboardTool.frequency)
--print(spoon.ClipboardTool.hist_size)
--print(spoon.ClipboardTool.menubar_title)
spoon.ClipboardTool:bindHotkeys({ toggle_clipboard={{"ctrl", "alt", "cmd"}, "4"} })
spoon.ClipboardTool:start()--]]
--[[hs.loadSpoon("LookupSelection")
spoon.LookupSelection:bindHotkeys({
lexicon = { { "ctrl", "alt", "cmd" }, "L" },
neue_notiz = { { "ctrl", "alt", "cmd" }, "N" },
hsdocs = { { "ctrl", "alt", "cmd" }, "H" },
})--]]
-- hs.loadSpoon("SpeedMenu")
--[[hs.loadSpoon("PopUpMenu")
spoon.PopUpMenu:bindHotkeys({ togglePopupMenu={{"ctrl", "alt", "cmd"}, "P"} })
spoon.PopUpMenu:start()--]]
--hs.loadSpoon("ColorPicker")
--spoon.ColorPicker.show_in_menubar = true
--spoon.ColorPicker:bindHotkeys({ show={{"ctrl", "alt", "cmd"}, "P"}})
--spoon.ColorPicker:start()
-- hs.loadSpoon("CountDown")
--[[hs.loadSpoon("DeepLTranslate")
spoon.DeepLTranslate:bindHotkeys({
translate = { { "ctrl", "alt", "cmd" }, "E" },
rephrase = { { "ctrl", "alt", "cmd" }, "G" },
})--]]
--[[ksheet_visible = false
function toggle_ksheet()
if ksheet_visible then
spoon.KSheet:hide()
ksheet_visible = false
else
spoon.KSheet:show()
ksheet_visible = true
end
end
hs.loadSpoon("KSheet")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "k", "KSheet", toggle_ksheet)--]]
--[[hs.loadSpoon("Commander")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "m", function() spoon.Commander:show() end)
--]]
--[[HSKeybindings_visible = false
function toggle_HSKeybindings()
if HSKeybindings_visible then
spoon.HSKeybindings:hide()
HSKeybindings_visible = false
else
spoon.HSKeybindings:show()
HSKeybindings_visible = true
end
end
hs.loadSpoon("HSKeybindings")
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "0", toggle_HSKeybindings)--]]
--[[hs.loadSpoon("FinderPopup")
spoon.FinderPopup:bindHotkeys({
finderPopup = { { "ctrl", "alt", "cmd" }, "C" },
})--]]
function requestHandler(type, path, headers, body)
print(type .. " " .. path)
print("body:" .. body)
print("headers:" .. hs.inspect.inspect(headers))
local response = [[{"data":{"k1":"v1", "k2":"v2"}]]
return response, 200, {}
end
server = hs.httpserver.new(true)
server:setPort(14141)
server:setCallback(requestHandler)
server:start()
function usbwatcherCallback(details)
print(hs.inspect.inspect(details))
end
usbwatcher = hs.usb.watcher.new(usbwatcherCallback)
usbwatcher:start()
hs.urlevent.bind("event1", function(event, paramtable)
print(event ..":".. hs.inspect.inspect(paramtable))
end)
hs.urlevent.bind("event2", function(event, paramtable)
print(event ..":".. hs.inspect.inspect(paramtable))
end)
hs.urlevent.httpCallback = function(scheme, host, params, fullURL)
print("hs.urlevent.httpCallback:" .. tostring(fullURL))
end
--[[
for minute = 1,9,2 do
local timestring = "11:"..minute
print(timestring)
hs.timer.doAt(timestring,"10m", test_function)
end
--]]
require("udp-listener")
require "wifiwatcher"
require "volumeswatcher"
--[[hs.logger.defaultLogLevel="info"
local log = hs.logger.new('myinit')
local dlog = hs.logger.new('myinit', "debug")
local vlog = hs.logger.new('myinit', "verbose")
log.v ("log.v verboseLevel")
vlog.v("vlog.v verboseLevel")
log.d ("log.d debugLevel")
dlog.d("dlog.d debugLevel")
log.i ("log.i infoLevel")
log.f ("log.f %s: %d %f", "infoLevel", 42, 1.5)
log.w ("log.w warningLevel")
log.e ("log.e errorLevel")--]]