apple-notes-mcp 2.8.45 → 2.8.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/index.js +76 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1174,6 +1174,8 @@ Creates a new folder, including a whole nested hierarchy in one call.
|
|
|
1174
1174
|
|
|
1175
1175
|
**Returns:** Confirmation message. The call is **idempotent** — an already-existing folder (or path segment) is skipped rather than treated as an error, so it is safe to call before every `create-note` that targets a folder.
|
|
1176
1176
|
|
|
1177
|
+
Existence is decided by folder id, not by name: a folder deleted earlier in the same Notes session no longer counts as existing, and the call succeeds only once the created folder is confirmed by its id. Otherwise it reports failure.
|
|
1178
|
+
|
|
1177
1179
|
---
|
|
1178
1180
|
|
|
1179
1181
|
#### `get-folder-by-id`
|
package/build/index.js
CHANGED
|
@@ -42321,6 +42321,58 @@ function buildFolderReference(folderPath) {
|
|
|
42321
42321
|
return parts.reverse().map((part) => `folder "${escapePlainStringForAppleScript(part)}"`).join(" of ");
|
|
42322
42322
|
}
|
|
42323
42323
|
var AS_ACCOUNT_REF = "__acctRef";
|
|
42324
|
+
var LIVE_FOLDER_NOT_FOUND = "Folder not found";
|
|
42325
|
+
function buildLiveFolderResolution(folderPath, varName, opts = {}) {
|
|
42326
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(varName)) throw new Error("Invalid AppleScript variable");
|
|
42327
|
+
buildFolderReference(folderPath);
|
|
42328
|
+
const parts = splitFolderPath(folderPath);
|
|
42329
|
+
const c = `${varName}_c`;
|
|
42330
|
+
const cid = `${varName}_cid`;
|
|
42331
|
+
const any = `${varName}_any`;
|
|
42332
|
+
const parent = `${varName}_p`;
|
|
42333
|
+
const notFound = `error "${LIVE_FOLDER_NOT_FOUND}: ${escapePlainStringForAppleScript(folderPath)}" number -1728`;
|
|
42334
|
+
const lines = [];
|
|
42335
|
+
parts.forEach((part, i) => {
|
|
42336
|
+
const name = escapePlainStringForAppleScript(part);
|
|
42337
|
+
if (i === 0) {
|
|
42338
|
+
lines.push(
|
|
42339
|
+
`set ${varName} to missing value`,
|
|
42340
|
+
`set ${any} to missing value`,
|
|
42341
|
+
`repeat with ${c} in (folders of ${AS_ACCOUNT_REF} whose name is "${name}")`,
|
|
42342
|
+
` try`,
|
|
42343
|
+
` set ${cid} to id of ${c}`,
|
|
42344
|
+
` if exists folder id ${cid} then`,
|
|
42345
|
+
` if class of (container of ${c}) is not folder then`,
|
|
42346
|
+
` set ${varName} to folder id ${cid}`,
|
|
42347
|
+
` exit repeat`,
|
|
42348
|
+
` else if ${any} is missing value then`,
|
|
42349
|
+
` set ${any} to folder id ${cid}`,
|
|
42350
|
+
` end if`,
|
|
42351
|
+
` end if`,
|
|
42352
|
+
` end try`,
|
|
42353
|
+
`end repeat`
|
|
42354
|
+
);
|
|
42355
|
+
if (!opts.rootOnly)
|
|
42356
|
+
lines.push(`if ${varName} is missing value then set ${varName} to ${any}`);
|
|
42357
|
+
} else {
|
|
42358
|
+
lines.push(
|
|
42359
|
+
`set ${parent} to ${varName}`,
|
|
42360
|
+
`set ${varName} to missing value`,
|
|
42361
|
+
`repeat with ${c} in (folders of ${parent} whose name is "${name}")`,
|
|
42362
|
+
` try`,
|
|
42363
|
+
` set ${cid} to id of ${c}`,
|
|
42364
|
+
` if exists folder id ${cid} then`,
|
|
42365
|
+
` set ${varName} to folder id ${cid}`,
|
|
42366
|
+
` exit repeat`,
|
|
42367
|
+
` end if`,
|
|
42368
|
+
` end try`,
|
|
42369
|
+
`end repeat`
|
|
42370
|
+
);
|
|
42371
|
+
}
|
|
42372
|
+
lines.push(`if ${varName} is missing value then ${notFound}`);
|
|
42373
|
+
});
|
|
42374
|
+
return lines.join("\n");
|
|
42375
|
+
}
|
|
42324
42376
|
var ACCOUNT_RESOLUTION_ERROR = "AccountResolutionError:";
|
|
42325
42377
|
function throwIfAccountResolutionFailed(error2) {
|
|
42326
42378
|
if (!error2) return;
|
|
@@ -42550,8 +42602,8 @@ var AppleNotesManager = class {
|
|
|
42550
42602
|
const safeBody = escapeHtmlForAppleScript(`<h1>${htmlTitle}</h1>${bodyContent}`);
|
|
42551
42603
|
let createCommand;
|
|
42552
42604
|
if (folder) {
|
|
42553
|
-
|
|
42554
|
-
|
|
42605
|
+
createCommand = `${buildLiveFolderResolution(folder, "__folder")}
|
|
42606
|
+
make new note at __folder with properties {body:"${safeBody}"}`;
|
|
42555
42607
|
} else {
|
|
42556
42608
|
createCommand = `
|
|
42557
42609
|
set newNote to make new note with properties {body:"${safeBody}"}
|
|
@@ -43663,10 +43715,10 @@ var AppleNotesManager = class {
|
|
|
43663
43715
|
}
|
|
43664
43716
|
for (let i = 0; i < parts.length; i++) {
|
|
43665
43717
|
const currentPath = parts.slice(0, i + 1).map((p) => escapeFolderName(p)).join("/");
|
|
43666
|
-
const currentRef = buildFolderReference(currentPath);
|
|
43667
43718
|
const checkScript = buildAccountScopedScript(
|
|
43668
43719
|
{ account: targetAccount },
|
|
43669
|
-
|
|
43720
|
+
`${buildLiveFolderResolution(currentPath, "__folder", { rootOnly: true })}
|
|
43721
|
+
return id of __folder`
|
|
43670
43722
|
);
|
|
43671
43723
|
const checkResult = executeAppleScript(checkScript);
|
|
43672
43724
|
if (checkResult.success) {
|
|
@@ -43678,8 +43730,8 @@ var AppleNotesManager = class {
|
|
|
43678
43730
|
createCommand = `make new folder with properties {name:"${segmentName}"}`;
|
|
43679
43731
|
} else {
|
|
43680
43732
|
const parentPath = parts.slice(0, i).map((p) => escapeFolderName(p)).join("/");
|
|
43681
|
-
|
|
43682
|
-
|
|
43733
|
+
createCommand = `${buildLiveFolderResolution(parentPath, "__parent", { rootOnly: true })}
|
|
43734
|
+
make new folder at __parent with properties {name:"${segmentName}"}`;
|
|
43683
43735
|
}
|
|
43684
43736
|
const script = buildAccountScopedScript({ account: targetAccount }, createCommand);
|
|
43685
43737
|
const result = executeMutationAppleScript(script);
|
|
@@ -43689,14 +43741,23 @@ var AppleNotesManager = class {
|
|
|
43689
43741
|
return null;
|
|
43690
43742
|
}
|
|
43691
43743
|
}
|
|
43692
|
-
const fullRef = buildFolderReference(name);
|
|
43693
43744
|
const idScript = buildAccountScopedScript(
|
|
43694
43745
|
{ account: targetAccount },
|
|
43695
|
-
|
|
43746
|
+
`${buildLiveFolderResolution(name, "__folder", { rootOnly: true })}
|
|
43747
|
+
return (id of __folder) & ${AS_FIELD_SEP} & (name of it)`
|
|
43696
43748
|
);
|
|
43697
43749
|
const idResult = executeAppleScript(idScript);
|
|
43698
43750
|
const [rawId = "", rawAccount = ""] = idResult.success ? idResult.output.split(FIELD_SEP) : [];
|
|
43699
|
-
const
|
|
43751
|
+
const bareId = rawId.trim();
|
|
43752
|
+
const folderId2 = !idResult.success ? "" : FOLDER_ID_PATTERN.test(bareId) ? bareId : extractCoreDataId(rawId, "folder");
|
|
43753
|
+
if (!folderId2) {
|
|
43754
|
+
throwIfAccountResolutionFailed(idResult.error);
|
|
43755
|
+
console.error(
|
|
43756
|
+
`Folder "${name}" could not be confirmed after creation:`,
|
|
43757
|
+
idResult.error ?? "no folder id returned"
|
|
43758
|
+
);
|
|
43759
|
+
return null;
|
|
43760
|
+
}
|
|
43700
43761
|
return {
|
|
43701
43762
|
id: folderId2,
|
|
43702
43763
|
name,
|
|
@@ -43714,7 +43775,8 @@ var AppleNotesManager = class {
|
|
|
43714
43775
|
*/
|
|
43715
43776
|
deleteFolder(name, account) {
|
|
43716
43777
|
const targetAccount = this.resolveAccount(account);
|
|
43717
|
-
const deleteCommand =
|
|
43778
|
+
const deleteCommand = `${buildLiveFolderResolution(name, "__folder")}
|
|
43779
|
+
delete __folder`;
|
|
43718
43780
|
const script = buildAccountScopedScript({ account: targetAccount }, deleteCommand);
|
|
43719
43781
|
const result = executeMutationAppleScript(script);
|
|
43720
43782
|
if (!result.success) {
|
|
@@ -43740,10 +43802,10 @@ var AppleNotesManager = class {
|
|
|
43740
43802
|
moveNoteById(id2, destinationFolder, account, scope2) {
|
|
43741
43803
|
const targetAccount = this.resolveAccount(account);
|
|
43742
43804
|
const safeId = sanitizeNoteId(id2);
|
|
43743
|
-
const
|
|
43805
|
+
const destFolderSetup = buildLiveFolderResolution(destinationFolder, "destFolder");
|
|
43744
43806
|
const moveCommand = `
|
|
43745
43807
|
${buildAccountResolution(targetAccount)}
|
|
43746
|
-
|
|
43808
|
+
${destFolderSetup}
|
|
43747
43809
|
set noteRef to note id "${safeId}"${buildScopeGuardScript("noteRef", scope2, "destFolder")}
|
|
43748
43810
|
move noteRef to destFolder
|
|
43749
43811
|
set movedNoteRef to note id "${safeId}"
|
|
@@ -44649,7 +44711,7 @@ var AppleNotesManager = class {
|
|
|
44649
44711
|
batchMoveNotes(ids, folder, account) {
|
|
44650
44712
|
if (ids.length === 0) return [];
|
|
44651
44713
|
const targetAccount = this.resolveAccount(account);
|
|
44652
|
-
const
|
|
44714
|
+
const destFolderSetup = buildLiveFolderResolution(folder, "destFolder");
|
|
44653
44715
|
const results = new Array(ids.length);
|
|
44654
44716
|
const runnable = [];
|
|
44655
44717
|
ids.forEach((id2, i) => {
|
|
@@ -44667,7 +44729,7 @@ var AppleNotesManager = class {
|
|
|
44667
44729
|
const idList2 = runnable.map((r) => `"${r.safe}"`).join(", ");
|
|
44668
44730
|
const script = buildAppLevelScript(`
|
|
44669
44731
|
${buildAccountResolution(targetAccount)}
|
|
44670
|
-
|
|
44732
|
+
${destFolderSetup}
|
|
44671
44733
|
set out to ""
|
|
44672
44734
|
repeat with rawId in {${idList2}}
|
|
44673
44735
|
set theId to (rawId as text)
|
package/package.json
CHANGED