Skip to content

Instantly share code, notes, and snippets.

@yoko
Last active March 21, 2020 18:59
Show Gist options
  • Save yoko/1fa219c2eb55ab6eb55992eecb692edc to your computer and use it in GitHub Desktop.
Save yoko/1fa219c2eb55ab6eb55992eecb692edc to your computer and use it in GitHub Desktop.
BathyScaphe Script
// 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, '&amp;')
.replace(/"/g, '&quot;')
.replace(/>/g, '&gt;')
.replace(/</g, '&lt;')
// タイトル以外をフォーマット
.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
}
@yoko
Copy link
Author

yoko commented Mar 21, 2020

AppleScriptから書き込む場合、結局フォーマットが改変されてしまう。スクリプトからメモアプリデフォルトのスタイルに合わせるのは難しそう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment