-
Notifications
You must be signed in to change notification settings - Fork 1
/
random.lua
172 lines (129 loc) · 4.68 KB
/
random.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
local mash = {"cmd", "alt", "ctrl"}
-----------------------------------------------------------------------------------
--/ shortcut to open applications /--
-----------------------------------------------------------------------------------
local appList = {
a = 'Activity Monitor',
f = "Finder",
s = 'Sublime Text 2'
}
for key, app in pairs(appList) do
hs.hotkey.bind(mash, key, function() hs.application.launchOrFocus(app) end)
end
------------------------------------------------------------------------------------
--/ wifi stuffs /--
------------------------------------------------------------------------------------
local homeWifi = "HOME-2172"
local urlToLoad = "https://www.twitter.com"
local browser = "Safari"
hs.wifi.watcher.new(function()
local ssid = hs.wifi.currentNetwork()
-- alert when internet is connected/disconnected
if not ssid then
hs.alert.show("wifi disconnected")
else
hs.alert.show("wifi connected")
end
-- load the url when home wifi is connected
if ssid == homeWifi then
-- wait for few seconds
hs.timer.doAfter(2, function()
-- load the url
hs.execute("open "..urlToLoad)
-- lunch or focus the app
hs.application.launchOrFocus(browser)
end)
end
end):start()
--toggle wifi
hs.hotkey.bind(mash, "W", function()
if hs.wifi.currentNetwork() == nil then
os.execute("networksetup -setairportpower en1 on")
else
os.execute("networksetup -setairportpower en1 off")
end
end)
------------------------------------------------------------------------------------
-- alert wifi up/down speed if speed goes below x%
--function speedDroppedCallback()
-- ssid = hs.wifi.currentNetwork()
--end
-- for key, app in pairs(hs.application.runningApplications()) do
-- --print("* "..app:title())
-- for key, window in pairs(app:visibleWindows()) do
-- --print(" --"..window:title())
-- end
-- end
--print(hs.application.frontmostApplication())
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- get all apps
-- Debug: for trying out snippets of code
-- function dbg()
-- apps = hs.application.runningApplications()
-- for appIndex=1,#apps do
-- app = apps[appIndex]
-- print( app:pid() .. ' ' .. app:title() )
-- end
-- end
-- dbg()
-- function listApps()
-- print('-- Listing Running Apps --');
-- hs.fnutils.each(hs.application.runningApplications(), function(app) print(app:bundleID(), app:title()) end)
-- print('------------');
-- end
border = nil
function drawBorder()
if border then
border:delete()
end
local win = hs.window.focusedWindow()
if win == nil then return end
local f = win:frame()
local fx = f.x - 2
local fy = f.y - 2
local fw = f.w + 4
local fh = f.h + 4
border = hs.drawing.rectangle(hs.geometry.rect(fx, fy, fw, fh))
border:setStrokeWidth(4)
--border:setFillColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=01})
border:setStrokeColor({["red"]=0,["blue"]=0,["green"]=1,["alpha"]=1})
border:setRoundedRectRadii(6.0, 6.0)
border:setStroke(true):setFill(false)
border:sendToBack():show()
end
-- drawBorder()
-- windows = hs.window.filter.new(nil)
-- windows:subscribe(hs.window.filter.windowCreated, function () drawBorder() end)
-- windows:subscribe(hs.window.filter.windowFocused, function () drawBorder() end)
-- windows:subscribe(hs.window.filter.windowMoved, function () drawBorder() end)
-- windows:subscribe(hs.window.filter.windowUnfocused, function () drawBorder() end)
-- Lets draw the bar, on as many screens as we have, across the top
function drawBottonBar()
local activeWindow = hs.window.frontmostWindow()
local frame = activeWindow:frame()
local box = hs.drawing.rectangle(hs.geometry.rect(frame.x, frame.h+3, frame.w, 20))
box:setFillColor({["red"]=0.1,["blue"]=0.1,["green"]=0.1,["alpha"]=0.5}):setFill(true):show()
box:setRoundedRectRadii(1.0, 1.0)
-- Create the iTunes box
local text = hs.drawing.text(hs.geometry.rect(frame.x , frame.h+3, frame.w, 20), "Test")
-- Set the text color
text:setTextColor({["red"]=1,["blue"]=1,["green"]=1,["alpha"]=1})
-- Set the font size and font type
text:setTextSize(14)
text:setTextFont('Tamzen7x14')
text:setClickCallback()
text:show()
box:setLevel(hs.drawing.windowLevels["floating"])
end
--drawBottonBar()
--hammerspoon://test1?someParam=hello
hs.urlevent.bind("test", function(eventName, params)
if params["someParam"] then
hs.alert.show(params["someParam"])
else
hs.alert.show("test")
end
end)
--hs.hotkey.bind(mash, '.', hs.hints.windowHints)