-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofile.lua
More file actions
78 lines (71 loc) · 2.44 KB
/
profile.lua
File metadata and controls
78 lines (71 loc) · 2.44 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
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
-- usage:
-- require('profile')
-- profile.getCurrentLocation()
-- usage:
-- local p = require('profile')
-- p.getCurrentLocation()
module = {}
module.locations = {
['A2DF6E86-2F00-481C-938E-3CC160347D26'] = {
name= 'Automatic',
-- browser = 'com.apple.Safari',
browser = 'com.google.Chrome',
},
['5AE03170-29FD-4ECE-B891-C72DCDB00712'] = {
name= 'Home',
browser = 'com.google.Chrome',
},
['90C23198-478B-4032-BBA0-A7024FB19797'] = {
name= 'YaoLG',
browser = 'com.google.Chrome',
},
['AE128892-4C47-400D-B784-7C5EB9A60442'] = {
name= 'Company',
browser = 'org.mozilla.firefox',
},
['E736F2F1-0DB3-47C6-A179-2779923A0021'] = {
name= 'JonieuNET',
browser = 'org.mozilla.firefox',
},
}
function module.getCurrentUUID()
local uuid = (hs.network.configuration.open():location():gsub('/Sets/', ''))
return uuid
end
function module.getCurrentProfile()
local uuid = (hs.network.configuration.open():location():gsub('/Sets/', ''))
return module.locations[uuid] or module.locations['A2DF6E86-2F00-481C-938E-3CC160347D26']
end
function module.setLocation(uuid)
local profile = module.locations[uuid]
hs.notify.new({title = '位置', informativeText = '已切换至「' .. profile.name .. '」'}):send()
print('WiFi位置:' .. profile.name)
return hs.network.configuration.open():setLocation(uuid)
end
-- -- https://igregory.ca/2020/hammerspoon-browser-picker/
-- function module.chooseBrowser()
-- local appBundle
-- local networkAddress = (hs.network.configuration.open():location():gsub('/Sets/', '')) -- scselect UUID
-- if networkAddress == 'E736F2F1-0DB3-47C6-A179-2779923A0021' then -- Jonieu.NET
-- appBundle = 'org.mozilla.firefox'
-- elseif networkAddress == '5AE03170-29FD-4ECE-B891-C72DCDB00712' then -- Home
-- appBundle = 'com.google.Chrome'
-- else
-- if host == nil then
-- host = 'file'
-- end
-- local script = 'choose from list {"Chrome", "Safari", "Firefox"} with prompt "Open ' .. fullURL .. ' with…"'
-- local success, _, res = hs.osascript.applescript(script)
-- local appBundle
-- if success and res:match('Chrome') ~= nil then
-- appBundle = 'com.google.Chrome'
-- elseif success and res:match('Safari') ~= nil then
-- appBundle = 'com.apple.Safari'
-- elseif success and res:match('Firefox') ~= nil then
-- appBundle = 'org.mozilla.firefox'
-- else
-- return
-- end
-- end
-- end
return module