-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvolumeswatcher.lua
67 lines (58 loc) · 2.43 KB
/
volumeswatcher.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
function volumeswatcherCallback1(ereignis, details)
local name = details.path
print(ereignis .. ": " .. hs.inspect.inspect(details))
if ereignis == hs.fs.volume.didMount then
hs.alert.show("Neues Dateisystem:" .. name )
elseif ereignis == hs.fs.volume.didUnmount then
hs.alert.show("Dateisystem " .. name .. " entfernt")
end
end
function volumeswatcherCallback2(ereignis, details)
local name = string.sub(details.path, 10)
print(ereignis .. ": " .. name)
if ereignis == hs.fs.volume.didMount then
hs.speech.new():speak("Neues Dateisystem:" .. name )
elseif ereignis == hs.fs.volume.didUnmount then
hs.speech.new():speak("Dateisystem " .. name .. " entfernt")
end
end
function volumeswatcherCallback3(ereignis, details)
if ereignis == hs.fs.volume.didMount then
hs.fs.volume.eject(details.path)
hs.speech.new():speak("Du kommst hier nicht rein!")
end
end
function volumeswatcherCallback4(ereignis, details)
if ereignis == hs.fs.volume.didMount then
write_log("volumeswatcher", "gesteckt: " .. details.path)
elseif ereignis == hs.fs.volume.didUnmount then
write_log("volumeswatcher", "entfernt:" .. details.path)
end
end
function volumeswatcherCallback5(ereignis, details)
local name = string.sub(details.path, 10)
print("volumeswatcherCallback5:" .. ereignis .. " " .. name)
if not (name == "Transcend") then return end
if ereignis == hs.fs.volume.didMount then
local zielverzeichnis = details.path .. "/hammerspoon-backup"
filemodus, error = hs.fs.attributes("/Volumes/Transcend/hammerspoon-backup", "mode")
if filemodus == "directory" then
hs.alert.show("Datensicherung nach " .. zielverzeichnis )
write_log("volumeswatcher", "Backup nach " .. zielverzeichnis)
local v1, v2, v3 = os.execute("cp -R ~/.hammerspoon " .. zielverzeichnis)
if v3 ~= 0 then
hs.dialog.blockAlert("Backup-Fehler", "Fehlercode von cp:" .. v3, "OK")
write_log("volumeswatcher", "Fehler beim cp " .. v3)
else
hs.alert.show("Backup Fertig")
write_log("volumeswatcher", "Backup OK")
end
else
hs.dialog.blockAlert("Backup-Fehler", error, "OK")
write_log("volumeswatcher", "Fehler beim backup nach " .. zielverzeichnis .. " - " .. error)
end
elseif ereignis == hs.fs.volume.didUnmount then
write_log("volumeswatcher", "entfernt:" .. details.path)
end
end
volumeswatcher = hs.fs.volume.new(volumeswatcherCallback5):start()