Skip to content

Clock with precise seconds #454

Answered by FelixKratz
lyra56k asked this question in Q&A
Dec 6, 2023 · 8 comments · 9 replies
Discussion options

You must be logged in to vote

Actually, it is really simple to create such C program:

#include "sketchybar.h"
#include <CoreFoundation/CoreFoundation.h>
#include <time.h>

void callback(CFRunLoopTimerRef timer, void* info) {
  time_t current_time;
  time(&current_time);
  const char* format = "%H:%M:%S";
  char buffer[64];
  strftime(buffer, sizeof(buffer), format, localtime(&current_time));

  uint32_t message_size = sizeof(buffer) + 64;
  char message[message_size];
  snprintf(message, message_size, "--set time label=\"%s\"", buffer);
  sketchybar(message);
}

int main() {
  CFRunLoopTimerRef timer = CFRunLoopTimerCreate(kCFAllocatorDefault, (int64_t)CFAbsoluteTimeGetCurrent() + 1.0, 1.0, 0, 0, callback, NULL);
  CF…

Replies: 8 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by FelixKratz
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@RainVier
Comment options

Comment options

You must be logged in to vote
3 replies
@FelixKratz
Comment options

@qns7
Comment options

@FelixKratz
Comment options

Comment options

You must be logged in to vote
5 replies
@lyra56k
Comment options

@vu1xan
Comment options

@lyra56k
Comment options

@vu1xan
Comment options

@lyra56k
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #453 on December 07, 2023 00:13.