Commit 10c0d64a19

10c0d64a19b13f9e27044e7dd3edb2b708038aed

parent: 71cfd8421d

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-22 01:13 UTC

Keep orgstar in the menu bar when asked

With menu-bar-item on, the menu bar item stays when no clock runs and its
menu adds Capture…, Agenda and today's open agenda entries.

Layout: unified · split

Sources/OrgApp/UserConfig.swift +2
@@ -391,6 +391,8 @@ public enum UserConfig {
391391 comment: "the Reminders lists shown, by title or identifier, separated by commas; \"\" for all", legacy: ""),
392392 Setting(section: "orgstar", key: "global-capture-hotkey", defaultsKey: "globalCapture", kind: .bool, fallback: .bool(true),
393393 comment: "⌃⌥Space opens Capture from any app; templates go in capture.toml", legacy: "capture.global-hotkey"),
394 Setting(section: "orgstar", key: "menu-bar-item", defaultsKey: "menuBarItem", kind: .bool, fallback: .bool(false),
395 comment: "keep orgstar in the menu bar, with capture and today's agenda; off shows it only while a clock runs", legacy: ""),
394396 ]
395397
396398 /// `"-3d"` as -3; nil for anything else.
Sources/Orgstar/ClockViews.swift +64 −14
@@ -15,6 +15,10 @@ func clockElapsed(_ running: ClockModel.Running, now: Date) -> String {
1515struct ClockMenuState: Equatable {
1616 let running: ClockModel.Running?
1717 let history: [ClockTask]
18 /// `menu-bar-item`: the item stays when no clock runs.
19 var always = false
20 /// Today's agenda, overdue entries first.
21 var today: [AgendaSnapshot.Row] = []
1822}
1923
2024/// `org-user-idle-seconds` on macOS: time since the last keyboard or mouse input anywhere.
@@ -62,21 +66,27 @@ struct ClockMenu: View {
6266 }
6367}
6468
65/// The menu bar item while a clock runs: elapsed time, and clock out, cancel and go to.
69/// The menu bar item: while a clock runs, the elapsed time and the clock commands; with
70/// `always`, there all the time, with capture, the agenda and today's entries too.
6671@MainActor
6772final class ClockStatusItem: NSObject {
73 /// Today's entries the menu lists before "more".
74 static let rowLimit = 12
75
6876 private var item: NSStatusItem?
6977 private var timer: Timer?
7078 private var running: ClockModel.Running?
7179 private let run: (String) -> Void
80 private let jump: (String, Int) -> Void
7281
73 init(run: @escaping (String) -> Void) {
82 init(run: @escaping (String) -> Void, jump: @escaping (String, Int) -> Void) {
7483 self.run = run
84 self.jump = jump
7585 }
7686
77 func update(_ running: ClockModel.Running?, recent: [String] = []) {
78 self.running = running
79 guard let running else {
87 func update(_ state: ClockMenuState) {
88 running = state.running
89 guard state.running != nil || state.always else {
8090 timer?.invalidate()
8191 timer = nil
8292 if let item { NSStatusBar.system.removeStatusItem(item) }
@@ -90,19 +100,42 @@ final class ClockStatusItem: NSObject {
90100 }
91101 }
92102 let menu = NSMenu()
93 menu.addItem(withTitle: running.heading, action: nil, keyEquivalent: "")
94 menu.addItem(.separator())
95 for (title, id) in [
96 ("Clock Out", "app.clock.out"), ("Cancel Clock", "app.clock.cancel"), ("Go to Clocked Entry", "app.clock.goto"),
97 ("Clock In to Recent Entry…", "app.clock.in-recent"), ("Clock Report", "app.clock.report"),
98 ] {
99 add(title, id, to: menu)
103 if state.always {
104 add(String(localized: "Capture…"), "app.capture", to: menu)
105 add(String(localized: "Agenda"), "app.agenda", to: menu)
106 menu.addItem(.separator())
107 menu.addItem(NSMenuItem.sectionHeader(title: String(localized: "Today")))
108 let rows = state.today.filter { !$0.isDone }
109 if rows.isEmpty { menu.addItem(withTitle: String(localized: "Nothing scheduled"), action: nil, keyEquivalent: "") }
110 for row in rows.prefix(Self.rowLimit) {
111 let title = [row.gutter, row.todo ?? "", row.title].filter { !$0.isEmpty }.joined(separator: " ")
112 let entry = NSMenuItem(title: title, action: row.link == nil ? nil : #selector(open(_:)), keyEquivalent: "")
113 entry.target = self
114 entry.representedObject = row.link
115 menu.addItem(entry)
116 }
117 if rows.count > Self.rowLimit { add(String(localized: "\(rows.count - Self.rowLimit) more…"), "app.agenda", to: menu) }
118 menu.addItem(.separator())
100119 }
120 var commands = [("Clock In to Recent Entry…", "app.clock.in-recent"), ("Clock Report", "app.clock.report")]
121 if let running = state.running {
122 menu.addItem(withTitle: running.heading, action: nil, keyEquivalent: "")
123 menu.addItem(.separator())
124 commands.insert(contentsOf: [("Clock Out", "app.clock.out"), ("Cancel Clock", "app.clock.cancel"), ("Go to Clocked Entry", "app.clock.goto")], at: 0)
125 }
126 for (title, id) in commands { add(title, id, to: menu) }
127 let recent = state.history.map(\.title)
101128 if !recent.isEmpty {
102129 menu.addItem(.separator())
103130 menu.addItem(NSMenuItem.sectionHeader(title: "Recent Entries"))
104131 for (index, title) in recent.enumerated() { add(title, "app.clock.history.\(index)", to: menu) }
105132 }
133 if state.always {
134 menu.addItem(.separator())
135 let show = NSMenuItem(title: String(localized: "Open orgstar"), action: #selector(activate), keyEquivalent: "")
136 show.target = self
137 menu.addItem(show)
138 }
106139 item?.menu = menu
107140 refresh()
108141 }
@@ -115,8 +148,14 @@ final class ClockStatusItem: NSObject {
115148 }
116149
117150 private func refresh() {
118 guard let running else { return }
119 item?.button?.title = "⏱ " + clockElapsed(running, now: Date())
151 guard let button = item?.button else { return }
152 if let running {
153 button.image = nil
154 button.title = "⏱ " + clockElapsed(running, now: Date())
155 } else {
156 button.image = NSImage(systemSymbolName: "star", accessibilityDescription: "orgstar")
157 button.title = ""
158 }
120159 }
121160
122161 @objc private func choose(_ sender: NSMenuItem) {
@@ -125,6 +164,17 @@ final class ClockStatusItem: NSObject {
125164 run(id)
126165 }
127166 }
167
168 @objc private func open(_ sender: NSMenuItem) {
169 if case .entry(let path, let offset)? = sender.representedObject as? AppLink {
170 NSApp.activate()
171 jump(path, offset)
172 }
173 }
174
175 @objc private func activate() {
176 NSApp.activate()
177 }
128178}
129179
130180/// Clocked time per day and heading (`ClockReport.timeReport`) for chosen files and dates.
Sources/Orgstar/ContentView.swift +13 −6
@@ -28,6 +28,9 @@ struct ContentView: View {
2828 @State private var hotKey: GlobalHotKey?
2929 @State private var statusItem: ClockStatusItem?
3030 @AppStorage("globalCapture") private var globalCapture = true
31 @AppStorage("menuBarItem") private var menuBarItem = false
32 /// Today's agenda for the menu bar item.
33 @State private var menuToday: [AgendaSnapshot.Row] = []
3134 @State private var hour = 0
3235 @AppStorage("saveMode") private var saveMode = SaveMode.automatic
3336 @AppStorage("keymap") private var preset = KeymapPreset.emacs
@@ -428,10 +431,11 @@ struct ContentView: View {
428431 var body: some View {
429432 main
430433 .task(id: workspace.files.count) { syncClock(paths: workspace.agendaFilePaths()) }
431 .onChange(of: ClockMenuState(running: clock.running, history: clock.history), initial: true) { _, state in
432 if statusItem == nil { statusItem = ClockStatusItem { commands.run($0) } }
433 statusItem?.update(state.running, recent: state.history.map(\.title))
434 .onChange(of: ClockMenuState(running: clock.running, history: clock.history, always: menuBarItem, today: menuToday), initial: true) { _, state in
435 if statusItem == nil { statusItem = ClockStatusItem(run: { commands.run($0) }, jump: { commands.jump(path: $0, offset: $1) }) }
436 statusItem?.update(state)
434437 }
438 .task(id: menuBarItem) { if menuBarItem { await updateWidgets() } }
435439 .onChange(of: globalCapture, initial: true) { _, enabled in
436440 hotKey?.unregister()
437441 hotKey = enabled ? GlobalHotKey { perform("app.capture") } : nil
@@ -1172,9 +1176,10 @@ struct ContentView: View {
11721176 }
11731177
11741178 /// The desktop widgets' agenda and habits, written where the widget extension reads them,
1175 /// with the widgets reloaded when they changed.
1179 /// with the widgets reloaded when they changed; and today's agenda for the menu bar item.
11761180 private func updateWidgets() async {
1177 guard !Task.isCancelled, ProAccess.shared.isUnlocked, !workspace.files.isEmpty, let file = AgendaSnapshot.file() else { return }
1181 let file = ProAccess.shared.isUnlocked ? AgendaSnapshot.file() : nil
1182 guard !Task.isCancelled, !workspace.files.isEmpty, file != nil || menuBarItem else { return }
11781183 let days = widgetAgenda ?? AgendaModel(workspace: workspace)
11791184 widgetAgenda = days
11801185 days.mode = .agenda(span: AgendaSnapshot.dayCount, startOffset: 0)
@@ -1192,10 +1197,12 @@ struct ContentView: View {
11921197 let open = session.openTexts
11931198 await days.refresh(open: open)
11941199 guard !Task.isCancelled else { return }
1200 let snapshot = AgendaSnapshot(groups: days.groups(), today: days.today, theme: theme, generated: Date())
1201 menuToday = snapshot.days.first.map { $0.overdue + $0.rows } ?? []
1202 guard let file else { return }
11951203 if (try? HabitSnapshot(habits: await days.habits(open: open), theme: theme).write()) == true {
11961204 WidgetCenter.shared.reloadTimelines(ofKind: "sh.krz.orgstar.habits")
11971205 }
1198 let snapshot = AgendaSnapshot(groups: days.groups(), today: days.today, theme: theme, generated: Date())
11991206 if (try? snapshot.write(to: file)) == true { WidgetCenter.shared.reloadAllTimelines() }
12001207 }
12011208
Sources/Orgstar/OrgstarApp.swift +3
@@ -707,6 +707,7 @@ struct SettingsView: View {
707707 @AppStorage("clockIdleTime") private var clockIdleTime = 0
708708 @AppStorage("clockHistoryLength") private var clockHistoryLength = 5
709709 @AppStorage("globalCapture") private var globalCapture = true
710 @AppStorage("menuBarItem") private var menuBarItem = false
710711 @AppStorage("settingsTab") private var tab = "general"
711712 @AppStorage("showHiddenFiles") private var showHiddenFiles = true
712713 @AppStorage("themeFont") private var themeFont = ""
@@ -821,6 +822,8 @@ struct SettingsView: View {
821822 ForEach(KeymapPreset.allCases, id: \.self) { Text($0.title).tag($0) }
822823 }
823824 Toggle("Show hidden files and folders", isOn: $showHiddenFiles)
825 Toggle("Keep orgstar in the menu bar", isOn: $menuBarItem)
826 .help("Capture, the agenda, today's entries and the clock, from any app. When off, the menu bar shows orgstar only while a clock runs.")
824827 Picker("Option as Meta", selection: $optionAsMeta) {
825828 Text("Left Option").tag(OptionAsMeta.left.rawValue)
826829 Text("Right Option").tag(OptionAsMeta.right.rawValue)
docs/manual/guide/06-dates-and-clocking.org +2
@@ -320,6 +320,8 @@ While a clock runs, orgstar shows it in three places, refreshed every 30 seconds
320320
321321The time shown is the time since you clocked in, not the entry's total. Each of them opens a menu with Clock Out, Cancel Clock and Go to Clocked Entry. The toolbar's menu also has Clock In to Recent Entry…, Go to Recent Clocked Entry… and the recent entries. The menu bar item also has Clock In to Recent Entry…, Clock Report and a Recent Entries section. Choosing a recent entry clocks in to it.
322322
323With Settings ▸ General ▸ Keep orgstar in the menu bar (=menu-bar-item=), the menu bar item stays when no clock runs, as a star, and its menu starts with Capture…, Agenda and today's agenda entries that aren't done, overdue ones first; choosing an entry shows it in the main window. It is there while orgstar is running.
324
323325** Recent entries
324326
325327orgstar keeps a clock history, as =org-clock-history=. Every clock-in, including one from the agenda or a capture template, puts the entry first in the history and removes its other entries there. The history holds =org-clock-history-length= entries (5 by default); the oldest go first.
docs/manual/guide/13-configuration.org +2
@@ -63,6 +63,7 @@ Open it with orgstar ▸ Settings (=⌘,=). It has six panes. The last, orgstar+
6363| Save files | Automatically, when typing stops; Only with File ▸ Save (=⌘S=) | Automatically | =save= |
6464| Keys | Emacs; Mac; Doom (Vim keys) | Emacs | =keymap= |
6565| Show hidden files and folders | On or off | On | =show-hidden-files= |
66| Keep orgstar in the menu bar | On or off | Off | =menu-bar-item= |
6667| Option as Meta | Left Option; Right Option; Both; Neither | Left Option | =option-as-meta= |
6768
6869Automatic saving writes a file one second after you stop typing. The keymap presets and =keymap.toml= are covered in [[file:03-keys.org][Keys and commands]].
@@ -426,6 +427,7 @@ Any other key in =[theme]= is a color; see Themes below.
426427| =agenda-reminders= | boolean | =false= | Show incomplete reminders with a due date from Reminders in the agenda, read-only. |
427428| =agenda-reminder-lists= | string | =""= | The Reminders lists shown, by title or identifier, separated by commas; =""= for all. |
428429| =global-capture-hotkey= | boolean | =true= | =⌃⌥Space= opens Capture from any app. |
430| =menu-bar-item= | boolean | =false= | Keep orgstar in the menu bar, with capture and today's agenda; off shows it only while a clock runs. |
429431
430432The default =ignored-folders= is:
431433
l10n/Localizable.xcstrings +102
@@ -1409,6 +1409,40 @@
14091409 }
14101410 }
14111411 },
1412 "%lld more…": {
1413 "localizations": {
1414 "de": {
1415 "stringUnit": {
1416 "state": "translated",
1417 "value": "%lld weitere …"
1418 }
1419 },
1420 "es": {
1421 "stringUnit": {
1422 "state": "translated",
1423 "value": "%lld más…"
1424 }
1425 },
1426 "fr": {
1427 "stringUnit": {
1428 "state": "translated",
1429 "value": "%lld de plus…"
1430 }
1431 },
1432 "ja": {
1433 "stringUnit": {
1434 "state": "translated",
1435 "value": "ほか%lld件…"
1436 }
1437 },
1438 "pt-BR": {
1439 "stringUnit": {
1440 "state": "translated",
1441 "value": "Mais %lld…"
1442 }
1443 }
1444 }
1445 },
14121446 "%lld open": {
14131447 "localizations": {
14141448 "de": {
@@ -5757,6 +5791,40 @@
57575791 }
57585792 }
57595793 },
5794 "Capture, the agenda, today's entries and the clock, from any app. When off, the menu bar shows orgstar only while a clock runs.": {
5795 "localizations": {
5796 "de": {
5797 "stringUnit": {
5798 "state": "translated",
5799 "value": "Erfassen, die Agenda, die heutigen Einträge und die Zeiterfassung aus jeder App. Wenn deaktiviert, zeigt die Menüleiste orgstar nur, während eine Zeiterfassung läuft."
5800 }
5801 },
5802 "es": {
5803 "stringUnit": {
5804 "state": "translated",
5805 "value": "Captura, la agenda, las entradas de hoy y el registro de tiempo, desde cualquier app. Si está desactivado, la barra de menús muestra orgstar solo mientras hay un registro de tiempo en curso."
5806 }
5807 },
5808 "fr": {
5809 "stringUnit": {
5810 "state": "translated",
5811 "value": "La capture, l'agenda, les entrées du jour et le chronométrage, depuis n'importe quelle app. Si désactivé, la barre des menus n'affiche orgstar que pendant un chronométrage."
5812 }
5813 },
5814 "ja": {
5815 "stringUnit": {
5816 "state": "translated",
5817 "value": "どのアプリからでも、キャプチャ、アジェンダ、今日のエントリ、クロックを使えます。オフの場合、クロックの実行中のみメニューバーにorgstarが表示されます。"
5818 }
5819 },
5820 "pt-BR": {
5821 "stringUnit": {
5822 "state": "translated",
5823 "value": "Captura, a agenda, as entradas de hoje e o registro de tempo, a partir de qualquer app. Quando desativado, a barra de menus mostra o orgstar apenas enquanto um registro de tempo está em andamento."
5824 }
5825 }
5826 }
5827 },
57605828 "Capture…": {
57615829 "comment": "Command title",
57625830 "localizations": {
@@ -16423,6 +16491,40 @@
1642316491 }
1642416492 }
1642516493 },
16494 "Keep orgstar in the menu bar": {
16495 "localizations": {
16496 "de": {
16497 "stringUnit": {
16498 "state": "translated",
16499 "value": "orgstar in der Menüleiste behalten"
16500 }
16501 },
16502 "es": {
16503 "stringUnit": {
16504 "state": "translated",
16505 "value": "Mantener orgstar en la barra de menús"
16506 }
16507 },
16508 "fr": {
16509 "stringUnit": {
16510 "state": "translated",
16511 "value": "Garder orgstar dans la barre des menus"
16512 }
16513 },
16514 "ja": {
16515 "stringUnit": {
16516 "state": "translated",
16517 "value": "orgstarをメニューバーに常に表示"
16518 }
16519 },
16520 "pt-BR": {
16521 "stringUnit": {
16522 "state": "translated",
16523 "value": "Manter o orgstar na barra de menus"
16524 }
16525 }
16526 }
16527 },
1642616528 "Keys": {
1642716529 "localizations": {
1642816530 "de": {