docs/manual/guide/17-command-line.org
122 lines · 8586 bytes
1#+TITLE: The command line
2#+DESCRIPTION: The orgstar command: the agenda as text or JSON, capture, clocking in and out, export, tangling and opening a file in the app, from Terminal and scripts.
3#+LEDE: The download version comes with an orgstar command that works on your files with the app's configuration, whether or not the app is running.
4
5* Installing the command
6
7The command is inside the app, at =orgstar.app/Contents/Helpers/orgstar=. To run it as =orgstar=:
8
9- Settings ▸ General ▸ Install Command-Line Tool… asks for a folder on your =PATH= and puts a link to the command there. =~/.local/bin= needs no administrator password; =/usr/local/bin= works when you can write to it. When orgstar can't write in the folder, the alert gives the =sudo ln -sf …= line to run in Terminal instead.
10- The Homebrew cask links it as =orgstar= when it installs the app.
11- A build from source has it at =.build/app/orgstar.app/Contents/Helpers/orgstar=.
12
13The link points into the app, so updating the app updates the command. The Mac App Store version has no command: its sandbox can't reach your files from another program.
14
15* What it reads
16
17The command reads the files the app reads and changes them the way the app does:
18
19- The configuration folder (see [[file:13-configuration.org][Configuration]]): =config.toml= for the settings, =capture.toml= for capture templates and =views.toml= for agenda views. Problems in them are printed as warnings.
20- The folders added in the app (File ▸ Add Folder…), from the app's data folder, =~/Library/Application Support/Orgstar=. =org-agenda-files= in =config.toml= chooses the agenda files as in the app.
21- Each file's own settings and =#+SETUPFILE:=.
22
23It doesn't need the app to be running. Choices kept only in the app are not read: folders hidden from the agenda, Calendar events and Reminders in the agenda, and each file's export choices.
24
25| Variable | What it sets |
26|-----------------------+------------------------------------------------------------------------------------------------------|
27| =ORGSTAR_CONFIG_DIR= | The configuration folder, instead of =$XDG_CONFIG_HOME/orgstar= or =~/.config/orgstar= |
28| =ORGSTAR_DATA_DIR= | The data folder, which holds the folder list, the running clock and recovery versions |
29| =ORGSTAR_ROOT= | A folder to read besides those added in the app |
30
31* Commands
32
33=orgstar --help= lists the commands, and =orgstar <command> --help= describes one. =orgstar --version= prints the app's version.
34
35** agenda
36
37#+BEGIN_SRC sh
38orgstar agenda
39orgstar agenda "TODO List"
40orgstar agenda Work --json
41#+END_SRC
42
43Prints the agenda as Emacs's agenda buffer shows it, with the span and start of Settings ▸ Agenda, the prefix format, sorting and time grid of =config.toml=. A name prints that view instead: TODO List, Stuck Projects, or a =[[view]]= of =views.toml=, block views included.
44
45#+BEGIN_EXAMPLE
46Week-agenda (W48):
47Friday 27 November 2026
48 8:00...... ----------------
49 tasks: 14:00-15:00 Meeting with Sam
50 tasks: Scheduled: TODO Write report
51 tasks: In 3 d.: TODO Pay rent :home:
52#+END_EXAMPLE
53
54=--json= prints the view's blocks, each with its header and its days and entries. An entry has its file, line and offset, category, keyword, title, tags, time and leader (=extra=), and the line as the text shows it.
55
56** capture
57
58#+BEGIN_SRC sh
59orgstar capture t "Buy milk"
60pbpaste | orgstar capture n
61orgstar capture m "Agenda for Monday" --set Who=Sam
62#+END_SRC
63
64Files an entry with the template of =capture.toml= that has that key, at once, as Shortcuts' Capture to Orgstar does. The text is =%i=: the argument, or standard input when there is none. =%?= is dropped.
65
66Questions are answered with =--set Prompt=value=, by the prompt's text: =%^{Who}= by =--set Who=…=. A question with a default (=%^{Room|Office}=) takes it when not set. A question with neither stops the capture with exit status 4 and names what to set, and nothing is written. Unset, =%^g= and =%^G= add no tags and the date questions take today; set them with =--set Tags=work:urgent= or =--set Date=+2d=. =%a=, =%c=, =%x= and =%f= are empty, since there's no buffer or clipboard. =%k= and =%K= are the running clock's entry.
67
68Targets work as in the app: a file is made when missing, =id= finds the heading in your folders, =clock= files under the running clock. =clock-in= with =clock-keep= starts the clock on the new entry; without =clock-keep= there's nothing to time, since the capture finishes at once. Templates with =denote = true= are refused; use them in the app.
69
70** clock
71
72#+BEGIN_SRC sh
73orgstar clock in work.org::"Write report"
74orgstar clock in id:0F3C2A1E-6B8D-4E3A-9B4F-2D1C0A9E8B7F
75orgstar clock status
76orgstar clock out
77#+END_SRC
78
79=clock in= starts the clock on a heading, named by its title (with or without a leading =*=), =#custom-id= or =id:ID=, after the file and =::=; =id:ID= alone looks in every folder. A running clock is clocked out first, as =org-clock-in= does. =clock out= stops the running clock. =clock status= prints the running clock, or with =--json= an object whose =running= is the clock or =null=; it exits with 3 when no clock runs.
80
81The command writes only the org file: the =CLOCK:= line, in the =LOGBOOK= drawer when =org-clock-into-drawer= says so, with the switch to =org-clock-in-switch-to-state= and the rounding and zero-time settings of =config.toml=. The running clock is the one the app shows when its line is still open, else the most recently started open =CLOCK:= line in the agenda files. The app watches your folders, so a clock started or stopped from the command line shows in the app as one started or stopped in Emacs does; the app's own record of the clock is never written by the command, so the two never write the same file.
82
83** export and tangle
84
85#+BEGIN_SRC sh
86orgstar export notes.org --to html
87orgstar export notes.org --to md -o -
88orgstar export notes.org --to odt -o ~/Desktop/notes.odt
89orgstar tangle init.org
90#+END_SRC
91
92Exports the whole file as File ▸ Export does, to =html=, =md=, =latex=, =txt=, =odt=, =reveal= or =pdf=, beside the file and named by =#+EXPORT_FILE_NAME= or the file's name, or to the path =-o= gives; =-o -= writes to standard output. Code in the HTML export isn't coloured. =pdf= runs the LaTeX export through =latexmk=, or =pdflatex= three times, as Emacs's =org-latex-export-to-pdf= does, so it needs TeX, such as MacTeX; the app's own PDF export doesn't.
93
94=tangle= writes the file's code blocks with =:tangle= to their files, as Tangle File (=C-c C-v t=) does, from the file as saved.
95
96** open
97
98#+BEGIN_SRC sh
99orgstar open notes.org
100orgstar open notes.org::"Reading list"
101orgstar open id:0F3C2A1E-6B8D-4E3A-9B4F-2D1C0A9E8B7F
102#+END_SRC
103
104Opens the file in orgstar, at the heading when one is named, through the app's =orgstar://entry= link. It starts orgstar when it isn't running.
105
106* How files are written
107
108The command saves a file the way the app saves one that isn't open: through a temporary file that replaces it, merged with any change made since it was read, and with the version it replaces kept for File ▸ History… as the app keeps them. Encrypted =.org.gpg= files and files that aren't UTF-8 are refused.
109
110There's no lock between the app and the command. A file open in orgstar takes in the command's change as it takes in one from Emacs: merged into the buffer, unsaved edits included, or shown as a conflict to resolve when both changed the same lines.
111
112* Exit status
113
114| Status | Meaning |
115|--------+--------------------------------------------------------------------------------------------------------------|
116| 0 | Done |
117| 1 | Failed: a file couldn't be read, written or exported, or it changed while being written |
118| 2 | Usage: an unknown command or option, or a missing argument |
119| 3 | Not found: no such file, heading, view or template; no running clock |
120| 4 | Refused: a capture question without an answer, or a file or command that needs the app |
121
122Messages go to standard error, prefixed with =orgstar:=.