简介
将用户输入文本快速添加为 FocusNote 今日笔记的子弹列表项,实现本地自动化日记记录。
原始描述
Add text to today's daily note in FocusNote as a new bullet point
中文使用说明 来自收录源
核心用法
focusnote-add-to-daily-note 是一个针对 FocusNote 笔记软件的自动化技能,允许用户通过命令行或脚本将任意文本快速追加到当天的日笔记中,格式化为标准子弹列表(bullet point)。其工作流程包括:读取 FocusNote 配置文件获取文档路径 → 生成当日日期 → 定位或创建日笔记目录 → 基于 Lexical 编辑器格式构建节点内容 → 分片存储节点文件 → 更新笔记结构索引。
显著优点
- 无缝集成:直接操作 FocusNote 的本地文件结构,无需官方 API,数据完全本地可控
- 自动化友好:纯 Node.js 实现,易于集成到各类自动化工作流(如定时任务、快捷键触发)
- 容错设计:自动创建缺失的日笔记目录和元数据文件,首次使用无感知
- 格式兼容:采用 FocusNote 底层使用的 Lexical 富文本格式,确保笔记在应用内正常渲染
- 性能优化:通过 UUID 前两位分片存储节点文件,避免单目录文件过多导致的性能问题
潜在缺点与局限性
- 依赖运行环境:必须安装 Node.js 和
uuid依赖包,对非技术用户不够友好 - 强耦合 FocusNote:直接操作私有文件格式,若 FocusNote 更新内部结构可能导致兼容性中断
- 无并发保护:多进程同时写入可能产生结构文件竞争条件,存在数据损坏风险
- 功能单一:仅支持追加子弹文本,不支持修改、删除、富文本格式或层级嵌套
- 无远程同步:纯本地操作,不触发 FocusNote 的云同步机制,需依赖应用自身的文件监控
适合人群
- 使用 FocusNote 作为主力笔记工具的深度用户
- 希望建立自动化日记/日志工作流的开发者和技术爱好者
- 需要快速捕捉碎片化想法,避免打开完整应用的操作极简主义者
- 配合 Alfred、Raycast、Keyboard Maestro 等工具构建快捷指令的高级用户
常规风险
| 风险类型 | 说明 | 缓解建议 |
|---|---|---|
| 数据完整性风险 | 直接修改 JSON 结构文件,格式错误可能导致笔记损坏 | 操作前备份 notes/ 目录,首次使用在测试笔记验证 |
| 版本兼容性风险 | FocusNote 更新可能更改文件格式 | 关注官方更新日志,遇到异常立即停用并检查结构变化 |
| 并发写入冲突 | 多实例同时运行可能导致 _structure.json 损坏 |
避免高频并发调用,或添加文件锁机制 |
| 配置依赖风险 | 依赖 ~/.lucia/documents-path.txt,若 FocusNote 未启动则失败 |
将 FocusNote 设为登录启动项,或硬编码备用路径 |
| 权限问题 | 无适当文件系统权限时写入失败 | 确保脚本运行用户对文档目录有读写权限 |
技能正文
name: focusnote-add-to-daily-note description: Add text to today's daily note in FocusNote as a new bullet point
FocusNote: Add to Daily Note
This skill adds user-provided text to today's daily note in FocusNote as a new bullet point.
How It Works
- Reads the FocusNote documents path from
~/.lucia/documents-path.txt - Generates today's date in
YYYY-MM-DDformat - Locates or creates today's daily note
- Adds the user's text as a new bullet point
- Updates the document's JSON structure files
Prerequisites
- FocusNote app must be running (it creates
~/.lucia/documents-path.txton startup) - Node.js installed for running the helper script
Implementation
When the user asks to add text to their daily note, follow these steps:
Step 1: Read Documents Path
const fs = require("fs");
const path = require("path");
const os = require("os");
// Read the documents path from FocusNote's config file
const focusnoteConfigPath = path.join(
os.homedir(),
".lucia",
"documents-path.txt",
);
const documentsPath = fs.readFileSync(focusnoteConfigPath, "utf-8").trim();
Step 2: Generate Today's Date
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, "0");
const day = String(today.getDate()).padStart(2, "0");
const todayDocName = `${year}-${month}-${day}`;
Step 3: Locate Daily Note Folder
const dailyNotePath = path.join(documentsPath, "notes", todayDocName);
const structurePath = path.join(dailyNotePath, "_structure.json");
const metadataPath = path.join(dailyNotePath, "_metadata.json");
const nodesDir = path.join(dailyNotePath, ".nodes");
Step 4: Create Daily Note If It Doesn't Exist
if (!fs.existsSync(dailyNotePath)) {
// Create directory structure
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
// Create metadata
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
// Create empty structure
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
Step 5: Create New Bullet Node
const { v4: uuidv4 } = require("uuid"); // npm install uuid
// Generate unique node ID
const nodeId = uuidv4();
const timestamp = Date.now();
// Create Lexical bullet structure
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: userText, // The text from the user
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "bullet",
start: 1,
tag: "ul",
},
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1,
},
};
// Create node object
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
Step 6: Save Node to Sharded Directory
// Shard by first 2 characters of node ID
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync(shardDir)) {
fs.mkdirSync(shardDir, { recursive: true });
}
const nodeFilePath = path.join(shardDir, `node-${nodeId}.json`);
fs.writeFileSync(nodeFilePath, JSON.stringify(newNode, null, 2));
Step 7: Update Structure File
// Read current structure
const structure = JSON.parse(fs.readFileSync(structurePath, "utf-8"));
// Add node to structure
structure.rootNodeIds.push(nodeId);
structure.nodes[nodeId] = {
parentId: null,
orderIndex: structure.rootNodeIds.length - 1,
childIds: [],
};
// Update timestamp
structure.updatedAt = timestamp;
// Save updated structure
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
Complete Script Example
Here's a complete Node.js script you can use:
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const os = require("os");
const { v4: uuidv4 } = require("uuid");
function addToDailyNote(userText) {
try {
// Step 1: Read documents path
const focusnoteConfigPath = path.join(
os.homedir(),
".lucia",
"documents-path.txt",
);
if (!fs.existsSync(focusnoteConfigPath)) {
throw new Error(
"FocusNote config file not found. Make sure FocusNote is running.",
);
}
const documentsPath = fs.readFileSync(focusnoteConfigPath, "utf-8").trim();
// Step 2: Generate today's date
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, "0");
const day = String(today.getDate()).padStart(2, "0");
const todayDocName = `${year}-${month}-${day}`;
// Step 3: Set up paths
const dailyNotePath = path.join(documentsPath, "notes", todayDocName);
const structurePath = path.join(dailyNotePath, "_structure.json");
const metadataPath = path.join(dailyNotePath, "_metadata.json");
const nodesDir = path.join(dailyNotePath, ".nodes");
// Step 4: Create daily note if needed
if (!fs.existsSync(dailyNotePath)) {
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
// Step 5: Create new bullet node
const nodeId = uuidv4();
const timestamp = Date.now();
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: userText,
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "bullet",
start: 1,
tag: "ul",
},
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1,
},
};
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
// Step 6: Save node file
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync(shardDir)) {
fs.mkdirSync(shardDir, { recursive: true });
}
const nodeFilePath = path.join(shardDir, `node-${nodeId}.json`);
fs.writeFileSync(nodeFilePath, JSON.stringify(newNode, null, 2));
// Step 7: Update structure
const structure = JSON.parse(fs.readFileSync(structurePath, "utf-8"));
structure.rootNodeIds.push(nodeId);
structure.nodes[nodeId] = {
parentId: null,
orderIndex: structure.rootNodeIds.length - 1,
childIds: [],
};
structure.updatedAt = timestamp;
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
console.log(`✅ Added bullet to ${todayDocName}: "${userText}"`);
return { success: true, documentName: todayDocName, nodeId };
} catch (error) {
console.error("❌ Error adding to daily note:", error.message);
return { success: false, error: error.message };
}
}
// Example usage
if (require.main === module) {
const userText = process.argv.slice(2).join(" ") || "New bullet point";
addToDailyNote(userText);
}
module.exports = { addToDailyNote };
Usage Examples
User: "Add to my daily note: Finished the OpenClaw skill implementation"
Assistant: I'll add that to your daily note.
# Run the script
node add-to-daily-note.js "Finished the OpenClaw skill implementation"
Output: ✅ Added bullet to 2026-02-11: "Finished the OpenClaw skill implementation"
User: "Add a reminder to call mom tomorrow"
Assistant: I'll add that to today's note.
node add-to-daily-note.js "Reminder to call mom tomorrow"
Installation
- Save the script as
add-to-daily-note.jsin your OpenClaw skills directory - Install dependencies:
npm install uuid - Make it executable:
chmod +x add-to-daily-note.js
Notes
- The skill creates a new bullet point each time it's called
- Bullets are added to the end of the daily note
- If the daily note doesn't exist, it will be created automatically
- The FocusNote app must be running for the documents path file to exist
- Changes are immediately visible when you open/refresh the daily note in FocusNote
Troubleshooting
Error: "FocusNote config file not found"
- Make sure FocusNote is running
- Check that
~/.lucia/documents-path.txtexists
Bullets not appearing in FocusNote
- Try closing and reopening the daily note
- Check that the node files were created in
.nodes/directory - Verify
_structure.jsonwas updated correctly
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。