2

I've been using this little utility to save out random thoughts through the day to a text file. I want to append the user input to an existing note in the notes APP, but can't figure out getting beyond simply calling the notes app. Any help would be greatly appreciated! Extra credit: If anyone has experience using Applescript to send data to a Google Sheet, I'd appreciate any resources - I have had a tough time finding any.

Thanks!

Here is my working script that logs user input to a text file.

set f to "/Users/Weston/Desktop/JAT.txt"
set myDate to date string of (current date)
set myTime to time string of (current date)
set myStamp to myDate & " " & myTime


set JAT to text returned of (display dialog "What's on your mind, Weston?" default answer " " with icon note buttons {"Cancel", "Continue"} default button "Continue")

set entry to return & ">" & myStamp & " | " & JAT

set myFile to open for access f with write permission
write entry to f starting at (get eof of f) + 1
close access myFile

quit
3
  • When you say you can't get beyond simply calling the Notes app you mean in Applescript I assume?
    – Natsfan
    Commented Jun 18, 2020 at 0:34
  • Yes, sorry I wasn't more clear! Commented Jun 18, 2020 at 1:00
  • you were fine. i just misunderstood.
    – Natsfan
    Commented Jun 18, 2020 at 1:15

1 Answer 1

2

This question explains how to modify text on Notes, so here's how that would be implemented in your code:

set noteName to "JAT"
set myDate to date string of (current date)
set myTime to time string of (current date)
set myStamp to myDate & " " & myTime


set JAT to text returned of (display dialog "What's on your mind, Weston?" default answer " " with icon note buttons {"Cancel", "Continue"} default button "Continue")

set entry to return & ">" & myStamp & " | " & JAT

tell application "Notes"
    tell account "iCloud"
        set body of note noteName to (get body of note noteName & entry)
    end tell
end tell

quit

Don't forget to create the note first, though.

4
  • Thank you for your reply! This is a running list of notes throughout the day - part of my issue is appending a new entry to the existing note without overwriting the existing entires. Commented Jun 18, 2020 at 1:01
  • You're welcome. So is the problem solved? My method technically overwrites the note, but copies it beforehand and puts it back in so it shouldn't be a problem.
    – htmlcat
    Commented Jun 18, 2020 at 2:00
  • You're right - that does the trick. Thank you again for your help! Commented Jun 18, 2020 at 4:12
  • Expect some formatting differences throughout the note. Notes are stored in an internal format, but when you read the note via the body property, you get an HTML representation of the content. Notes styles like Title and Heading will be changed to HTML versions (ex: <h2>) and may look different.
    – Mat Gessel
    Commented Sep 23 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .