Display the Time Fairly Large in the Middle of the Screen

Extra points for configurable font face, size, and style.

Even more extra points for configurable background color.

More for translucency, with no background color at all an option.

Or votes for wanting me to do it.

1 Like

Display Text Large does that, though it has no configuration.

Yes, thanks for pointing that out.

I was hoping for something a little less overwhelming that could go in a part of my screen that fit with my Application and window layout. (I know I said centered, but on further thought that’s another thing I would like control over.)

@MitchellModel, I don't think Keyboard Maestro is well suited for this type of task. You may want to do an Internet search and/or Mac app store search, for "date/time display" or similar. Some time ago I had a need for a live count-down timer and found several in the App Store.


####EDIT: 2016-05-14 15:29 CT (Sat)
I stand corrected. Keyboard Maestro is very well suited for this task.
See:


Here is one, called Timer for Mac

OK, I very much gave the wrong impression of what I was looking for. I don’t want a timer. What I need is the time displayed in response to a keystroke. It saves driving all the way up to the menubar clock and coming back to where you were. Besides, my eyesight is not good enough to read the menubar clock from where I sit relative to my MacBook and 27" external screen. Plus, there’s the weirdness of which screen controls the menubar (the one that’s bright, not shaded).

On further thought, what I really want is for the time to popup at my mouse, ideally with configurable size, typeface, style, etc., and maybe background color and translucency.

Search is your friend. :grinning:

Here’s good enough for now, but it still seems like a fun project for someone, even if it is all done in AppleScript. Or JXA. Or just go all in and write something in Xcode.

-- Mitchell Model, May 2016, slightly simplified from the first relevant script
-- I found with a web search, at 
-- http://alvinalexander.com/blog/post/mac-os-x/an-applescript-subroutine-that-returns-current-time-as-hours-mi


-- Get the "hour"
set timeStr to time string of (current date)
set Pos to offset of ":" in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string

-- Get the "minute"
set Pos to offset of ":" in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string

--Get "AM or PM"
set Pos to offset of " " in timeStr
set theSfx to characters (Pos + 1) through end of timeStr as string

display alert ((theHour & ":" & theMin & " " & theSfx) as string)

though come to think of it I am not sure what all that complication is about, except perhaps to eliminate seconds. The following is almost as good:

display alert the time string of (current date)

Hey Mitchell,

# AppleScript using the Satimage.osax { http://tinyurl.com/dc3soh }
display alert (strftime (current date) into "%H:%M %S")
# AppleScript using the shell
display alert (do shell script "date \"+%H:%M %S\"")

Straight-up Keyboard Maestro:

The Current Time.kmmacros (1.7 KB)

Using FastScripts as the display mechanism:

# Satimage.osax { http://tinyurl.com/dc3soh }
set timeStr to (strftime (current date) into "%H:%M %S")

tell application "FastScripts"
  display message timeStr ¬
    dismissing after delay 10 ¬
    at screen position top right
end tell

There used to be an AppleScript osax that allowed the display of styled text in a window that could be sized and positioned, but it didn't survive the jump to OSX.

-Chris

Another option if you want more control over the display would be to use the Custom HTML Prompt action.

1 Like

And the excellent @mattgemmell has made something like this. With calendar, time and extra info.


Scroll down to Heads-Up Info Display.

4 Likes

Like it!

Improved version :grin:

display alert the time string of (current date) giving up after 1
1 Like

Jimmy, thanks for pointing us to this great macro by @mattgemmell.

I guess I'll have to eat my words:

Clearly, in the right hands, Keyboard Maestro is VERY MUCH up to this task.

I really liked this macro, but wanted it to show a live clock. So, I have made a small revision:

4 Likes

That’s a very nice little macro! Is there a way to get it to show a 12 hour clock instead?

1 Like

Yep, just edit the JavaScript to format the time as you like.

1 Like

It looks like this might be Ruby. Any idea which line I can find it on? I tried searching for time, format, and 24 in the calendar.rb and calendar-config-html.yml files. I’m only seeing things that seem to be for dates. I may be missing it.

I’m not much of a scripter. All I can do is tweak – if I’m lucky.

1 Like

Nope, it is JavaScript in the calendar.html file:

function startTime() {
    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();
    m = checkTime(m);
    s = checkTime(s);
    document.getElementById('time').innerHTML =
    h + ":" + m + ":" + s;
    var t = setTimeout(startTime, 500);
}

This line sets the time display:

document.getElementById('time').innerHTML =
    h + ":" + m + ":" + s;

You just need to do the calculation to convert 24HR time to 12HR time, and set the display.

1 Like

I downloaded this macro/app and it works, on Big Sur no less, this is great, thank you @mattgemmell! @veramilo I wanted the 12 hr style too, enough to spend (too much, albeit fun) time learning how. At the time of writing this, I tweaked the file calendar.html to get a 12 hr style.

TL;DR    My slightly edited version of the calendar.html to display time in 12 hr style:
calendar.html.zip (2.1 KB)




If you would like to make the changes yourself or customize further, these are the three changes I made ↓.

Tokens are used to set the time (1). To change the clock style to 12hr style, I changed the Token in line 206 from:

%ICUDateTime%HH:mm%

to:

%ICUDateTime%h:mm a%

The space in 'mm a' puts a space after the time and "am/pm". This outgrows the margin and pushes everything down:


I remedied this by changing the font size: on line 46, changed "4rem" down to "3.7rem." You can of course just get rid of the space.

The am/pm displays in uppercase. I preferred lowercase so I added two lines of code, lines 203 & 204 in image below, and substituted variable res to the second half of what is now line 209 (2).



Appendix
Something that tripped me up for a while (because I didn't read the documentation as one should): press Esc. to exit, as ⌘W does not close the macro's pop up window at the time of this posting.

(1) See Keyboards Maestro Wiki's page on Tokens for more info on Tokens.
(2) See W3school' page on String toLowerCase() for more info on lines 203 & 204.
*See mattgemmell.com for the micro :).
*@JMichaelTX has a version that shows seconds which you should check out :).
*I am new to posting, lmk suggestions for posting better :O.

I just eared a badge for @mention, I thought this just tags the person, it look like it sends them a notification too? Which did not mean to do, still learning.