]> j8takagi.net Git Repository - txt2notesapp.git/commitdiff
first commit
authorj8takagi <j8takagi@nifty.com>
Fri, 1 Aug 2025 07:06:07 +0000 (16:06 +0900)
committerj8takagi <j8takagi@nifty.com>
Fri, 1 Aug 2025 07:06:07 +0000 (16:06 +0900)
Makefile [new file with mode: 0644]
README.md [new file with mode: 0644]
txt2noteapp.applescript [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..2eb7996
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+OSACOMPILE := osacompile
+INSTALL := install
+INSTALLDIR := ~/Library/Scripts
+TARGET := txt2noteapp.scpt
+
+all: $(TARGET)
+
+install: $(TARGET)
+       $(INSTALL) $< $(INSTALLDIR)/
+
+%.scpt: %.applescript
+       $(OSACOMPILE) -o $@ $<
+
+distclean:
+       $(RM) $(TARGET)
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..954042e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,34 @@
+# txt2memo.scpt
+
+AppleScript to send the contents of a plain text (`.txt`) file to the macOS Notes app as a new note.
+
+## Features
+
+- Uses the first line of the file as the note title
+- Converts each line of the text into a separate line in the note
+- Optionally converts line breaks to `<br>` (HTML-style line breaks)
+- Supports automatic tagging using lines that begin with `#` (Notes app tags)
+
+## Requirements
+
+- macOS 11.0 or later
+- Notes app
+- Terminal access (`osascript`)
+- Input file must be a plain text file encoded in **UTF-8**.
+
+## Installation
+
+To install the AppleScript file:
+
+```sh
+make install
+
+This will install the script to: `~/Library/Scripts/`
+
+
+## Usage
+
+From the terminal:
+
+```sh
+osascript ~/Library/Scripts/txt2memo.scpt /path/to/textfile.txt
diff --git a/txt2noteapp.applescript b/txt2noteapp.applescript
new file mode 100644 (file)
index 0000000..2173500
--- /dev/null
@@ -0,0 +1,37 @@
+on run argv
+    set filePath to item 1 of argv
+    try
+        open for access filePath
+        set fileContent to read filePath as «class utf8»
+    on error
+    end try
+    close access filepath
+
+    if (count of paragraphs of fileContent) = 0 then
+        display dialog "The file is empty." buttons {"OK"} default button "OK"
+        return
+    end if
+
+    set titleLine to paragraph 1 of fileContent
+    set bodyLines to rest of paragraphs of fileContent
+
+    my createNote(titleLine, my addBr(bodyLines))
+end run
+
+on addBr(linesList)
+    set outputText to ""
+    repeat with aLine in linesList
+        set outputText to outputText & aLine & "<br>" & return
+    end repeat
+    return outputText
+end addBr
+
+on createNote(titleText, bodyText)
+    tell application "Notes"
+        tell account "iCloud"
+            tell folder "Notes"
+                make new note with properties {name:titleText, body:bodyText}
+            end tell
+        end tell
+    end tell
+end createNote