Skip to content

Instantly share code, notes, and snippets.

@gargolito
Last active July 2, 2020 22:15
Show Gist options
  • Save gargolito/5b61fef43671f4fa7278bc070bf34271 to your computer and use it in GitHub Desktop.
Save gargolito/5b61fef43671f4fa7278bc070bf34271 to your computer and use it in GitHub Desktop.
Transparent clock, set as always on top and you can still click on any application behind/under the clock.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Digital Clock</title>
<meta charset="UTF-8">
<style>
body {
background: rgba(0, 0, 0, 0);
}
.clock {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
color: rgba(0, 250, 0, 0.5);
background-color: rgba(0, 0, 0, 0);
font-size: 9em;
font-family: monospace;
font-weight: bold;
letter-spacing: -14px;
}
</style>
</head>
<body>
<div id="MyClockDisplay" class="clock"></div>
<script>
function showTime(){
var date = new Date();
var h = date.getHours(); // 0 - 23
var m = date.getMinutes(); // 0 - 59
var s = date.getSeconds(); // 0 - 59
h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;
s = (s < 10) ? "0" + s : s;
var time = h + ":" + m + ":" + s;
document.getElementById("MyClockDisplay").innerText = time;
document.getElementById("MyClockDisplay").textContent = time;
setTimeout(showTime, 1000);
}
showTime();
</script>
</body>
</html>
I couldn't find a free desktop clock for MacOS and this solution wourked out great.
1. save clock.html
2. For MacOS only: install geektool https://www.tynsoe.org/v2/geektool/
3. drag a Web geeklet to desktop.
4. use file:///path/to/file.html in the url box
5. resize and position to your preference.
#!/usr/bin/env python
from subprocess import getoutput as run
try:
from AppKit import NSScreen
except ImportError:
run("pip install AppKit==0.2.8")
from argparse import ArgumentParser
parser = ArgumentParser(description="move geektools geeklet to bottom corner of requested monitor, defaults to bottom left corner of primary display")
parser.add_argument('-br', help = 'lower right of built-in display, use when monitor(s) attached and primary is not built-in', action = "store_true")
parser.add_argument('-bl', help = 'lower left of built-in display, use when monitor(s) attached and primary is not built-in', action = "store_true")
parser.add_argument('-pr', help = 'lower right of primary display, use when monitor(s) attached and primary is not built-in', action = "store_true")
parser.add_argument('-pl', help = 'lower left of primary display, use when monitor(s) attached and primary is not built-in', action = "store_true")
parser.add_argument('-sr', help = 'lower right of secondary display, use with two monitors monitor(s) attached', action = "store_true")
parser.add_argument('-sl', help = 'lower left of secondary display, use with two monitors monitor(s) attached', action = "store_true")
args = parser.parse_args()
if True not in args.__dict__.values():
parser.print_help()
args.pl = True
def mvclock(X = 0, Y = 0):
"""
generate applescript with coordinates where to move the geeklet and run it
if X and Y are not passed, defaults to lower left corner of the primary display
Args:
X (int, optional): [description]. Defaults to 0.
Y (int, optional): [description]. Defaults to 0.
"""
mv = f'osascript << _EOF_\n\
tell application "GeekTool Helper"\n\
set x of geeklet id "00449E55-484E-4A61-9247-54ED5E7B9B1E" to {X}\n\
set y of geeklet id "00449E55-484E-4A61-9247-54ED5E7B9B1E" to {Y}\n\
end tell\n_EOF_\n'
run(f"{mv}")
def get_dimensions_origin(n):
"""
get visible frame of each monitor from given list: n
Args:
n = index of monitor detected
Returns:
list: [monitor name, width, height, x coord, y coord]
"""
monitor = monitors[n]
mvf = monitor.visibleFrame()
x = int(mvf.origin.x)
y = int(mvf.origin.y)
w = int(mvf.size.width)
h = int(mvf.size.height)
return [monitor.localizedName(), w, h, x, y]
def get_displays(m):
"""
get all attached displays and adjust value of x and y
Args:
m = (x, y)
Returns:
tuple: (int, int)
"""
for mon in range(len(monitors)):
m = get_dimensions_origin(mon)
if args.br or args.pr or args.bl or args.pl:
if 'built-in' in m[0].lower():
if args.br: return m[1] + m[3] - 394, m[4] + 26 # l_right
if args.bl: return m[3] - 26, m[4] + 26 # l_left
else:
if args.pr: return m[1] - 394, m[4] + 26 # l_right width of screen - visible width of clock
if args.pl: return m[3] - 26, m[4] + 26 # l_left
else:
if args.sr: return (m[1] * 2) - 394, m[4] + 26 # l_right 2 * width of screen - visible width of clock
if args.sl: return m[1] - 26, m[4] + 26 # l_left
if __name__ == '__main__':
monitors = list(NSScreen.screens())
x, y = get_displays(monitors)
mvclock(x, y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment