An Org File working as a Config-File
A good file format saves coding a configuration-programYou may have noticed on the Fediverse that I haven't been trying to permanently configure my Stream Deck lately. Instead, I've built my own solution.
This solution consists of two components. First, a client running on my phone that displays 32 buttons with small images on the screen. Second, a server called DeckServer that pushes different button layouts (which I would normally see on the Stream Deck) to this client.
The Problem
The DeckServer runs as a background service with no user interface. To configure the buttons it should push to the client, I would normally need a small program with a GUI where I could assign images to individual buttons, define which commands each button should execute, and manage switching between layouts.
However, after some thought, I realized there's a much simpler solution. After all, I live in my Emacs editor, especially in Org-mode.
Org-mode files, like Windows configuration files, are hierarchical but can manage many more levels.
A typical hierarchy in Org-Mode could look like this:
- Main (e.g. = Stream Deck Buttons=)
- Subcategory* (e.g.
** Layouts)- SubSubcategory* (e.g.
*** Button 1)- Attributes (e.g.
:BILD: ~/bilder/start.png,:Befehl: systemctl start ...)
- Attributes (e.g.
- SubSubcategory* (e.g.
- Navigation (z. B.
** Layout-Wechsel)
- Subcategory* (e.g.
A key feature of Org-mode that worked well for DeckService configuration is tables.
The Solution
Tables in Org-Mode are constructed using = | = (pipe), = = (hyphen), and = + = (plus):
| Spalte 1 | Spalte 2 | Spalte 3 |
|----------+----------+----------|
| Wert A | Wert B | Wert C |
| Wert D | Wert E | Wert F |
- Rows: Each row starts and ends with
=|=. - Separator line: A line with
==(at least 2) and=+=defines the columns. - Alignment : When entering data, Org-Mode automatically aligns columns based on the longest entry.
If you make changes (e.g., a longer command), Org-Mode adjusts the column width accordingly.
| Name | Befehl | Icon |
|----------+-----------------+---------------|
| Start | systemctl start | ~/icons/start |
| Stop | systemctl stop | ~/icons/stop |
o, I simply wrote a layout in Org Mode exactly as I wanted it. To do this, I wrapped it under two headings. At the top level, just the word Layout, and below it, a heading with the name of this specific layout.
* Layouts
** Haptmenü
|--------+------+----------+-------+--------+-------+--------+---|
| Home | Mail | Internet | Emacs | Musik | Video | | |
|--------+------+----------+-------+--------+-------+--------+---|
| | | | | | | | |
|--------+------+----------+-------+--------+-------+--------+---|
| | | | | | | | |
|--------+------+----------+-------+--------+-------+--------+---|
| Zurück | Stop | Pause | Vor | Leiser | Stumm | Lauter | |
|--------+------+----------+-------+--------+-------+--------+---|
In the third level, I then compiled the properties for each of the buttons labeled above under their own respective headings. For example, it looked like this:
*** Home
:PROPERTIES:
:Label: Home
:Image: /home/andy/ablage/icons/WhiteOnBlack/128/Very-Basic-Home-Filled-icon.png
:Actions: Layout
:Parameters: Home
:Color: #000000
:END:
*** Emacs
:PROPERTIES:
:Label: Emacs
:Image: emacs.png
:Actions: Layout, Execute
:Parameters: EmacsMain, emacs
:Color: #000000
:END:
As you can see, for each button, it is defined what label should appear on it, which image to use, and what should happen when the button is pressed. In the case of the Emacs button, for example, the layout switches to the EmacsMain layout, and then the command emacs is executed on the command line.
The Advantages
The advantages are obvious:
- If I spontaneously think of additional configuration options, I can simply add them to the file and tweak the parser in the server for this file a little.
- If I want to create another layout, I just copy an existing one and change the labels in the table. Done.
- For buttons that do similar things, I can simply copy them and directly modify the differences.
All of this in the editor that I have open all day anyway: Emacs.