Last active
March 21, 2020 18:59
-
-
Save yoko/1fa219c2eb55ab6eb55992eecb692edc to your computer and use it in GitHub Desktop.
BathyScaphe Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// debugger | |
const BathyScaphe = Application('BathyScaphe') | |
const selectedText = BathyScaphe.documents[0].selectedText() | |
const threadTitle = BathyScaphe.documents[0].threadTitle() | |
const threadURL = BathyScaphe.documents[0].threadURL() | |
const Notes = Application('Notes') | |
const notes = Notes.defaultAccount.folders['📒Clipping'].notes | |
const note = notes[threadTitle] | |
// ノートのフォーマット | |
// Title : <div><h1>Title</h1></div> | |
// Heading : <div><h2>Heading</h2></div> | |
// Subheading: <div><h3>Subheading</h3></div> | |
// Body : <div>Body</div> | |
// Blank line: <div><br></div> | |
const body = selectedText | |
// HTMLエスケープ | |
.replace(/&/g, '&') | |
.replace(/"/g, '"') | |
.replace(/>/g, '>') | |
.replace(/</g, '<') | |
// タイトル以外をフォーマット | |
.replace(/^((?!\d+ 名前:).+)$/mg, (_, $1) => { | |
return `<div>${$1.trim()}</div>` | |
}) | |
// タイトルをフォーマット | |
.replace(/^(\d+ 名前:.+)$/mg, (_, $1) => { | |
return '<div><br></div>\n<div><br></div>\n' + `<div>${$1.trim()}</div>\n` + '<div><br></div>' | |
}) | |
// 改行の調整 | |
.replace(/\n{2,}/g, '\n<div><br></div>\n') | |
if (!note.exists()) { | |
notes.push(Notes.Note({ | |
body: `<div><h1>${threadTitle}</h1></div>\n<div><br></div>\n<div>${threadURL}</div>\n${body}`, | |
})) | |
} | |
else { | |
note.body = note.body() + body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AppleScriptから書き込む場合、結局フォーマットが改変されてしまう。スクリプトからメモアプリデフォルトのスタイルに合わせるのは難しそう。