技能 编程开发 苹果备忘录JXA开发循环

苹果备忘录JXA开发循环

v20260423
apple-notes-local-dev-loop
本工具为使用JXA(JavaScript for AppleScript)进行苹果备忘录自动化的开发流程提供支持。它集成了文件监听热重载功能和完善的测试辅助函数,允许开发者在本地环境快速迭代和测试笔记的增删改查操作,极大地提高了开发效率。
获取技能
330 次下载
概览

Apple Notes Local Dev Loop

Overview

Iterative development workflow for Apple Notes JXA scripts with file watching and test helpers.

Instructions

Step 1: Project Setup

mkdir apple-notes-automation && cd apple-notes-automation
npm init -y
npm install -D chokidar tsx typescript

Step 2: JXA Runner with Hot Reload

// src/dev/watch-runner.ts
import { watch } from "chokidar";
import { execSync } from "child_process";

watch("scripts/*.js", { ignoreInitial: true }).on("change", (path) => {
  console.log(`Changed: ${path} — running...`);
  try {
    const output = execSync(`osascript -l JavaScript "${path}"`, { encoding: "utf8" });
    console.log(output);
  } catch (err: any) {
    console.error(err.stderr);
  }
});

console.log("Watching scripts/*.js for changes...");

Step 3: Test Helper

// src/dev/test-notes.ts
import { execSync } from "child_process";

function runJxa(script: string): string {
  return execSync(`osascript -l JavaScript -e '${script}'`, { encoding: "utf8" }).trim();
}

function getNoteCount(): number {
  return parseInt(runJxa("Application(\"Notes\").defaultAccount.notes.length"));
}

function createTestNote(title: string): string {
  return runJxa(`
    const Notes = Application("Notes");
    const note = Notes.Note({name: "${title}", body: "<p>Test</p>"});
    Notes.defaultAccount.folders[0].notes.push(note);
    note.id();
  `);
}

export { runJxa, getNoteCount, createTestNote };

Step 4: Dev Scripts

{
  "scripts": {
    "dev": "tsx src/dev/watch-runner.ts",
    "test:notes": "tsx src/dev/test-notes.ts"
  }
}

Output

  • Hot-reload JXA development with file watching
  • Test helpers for note CRUD operations
  • Iterative script development workflow

Resources

信息
Category 编程开发
Name apple-notes-local-dev-loop
版本 v20260423
大小 2.33KB
更新时间 2026-04-28
语言