Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First working version #2

Closed
simonw opened this issue Mar 9, 2023 · 7 comments
Closed

First working version #2

simonw opened this issue Mar 9, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Collaborator

simonw commented Mar 9, 2023

It's going to shell out to osascript as seen in:

I'm going with that option because https://appscript.sourceforge.io/status.html warns against the other potential methods:

Apple eliminated its Mac Automation department in 2016. The future of AppleScript and its related technologies is unclear. Caveat emptor.

But osascript looks pretty stable to me.

@simonw simonw added the enhancement New feature or request label Mar 9, 2023
@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

I think the AppleScript I want to pass to osascript looks like this:

tell application "Notes"
   repeat with eachNote in every note
      set noteId to the id of eachNote
      set noteTitle to the name of eachNote
      set noteBody to the body of eachNote
      log "------------------------" & "\n"
      log noteId & "\n"
      log noteTitle & "\n\n"
      log noteBody & "\n"
   end repeat
end tell

But there are a few more properties I'd like to get - created and updated date for example.

@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

I opened the "Script Editor" app on my computer, used Window -> Library to open the Library panel, then clicked on the Notes app there. I got this:

image

So the notes object has these properties:

  • name (text) : the name of the note (normally the first line of the body)
  • id (text, r/o) : the unique identifier of the note
  • container (folder, r/o) : the folder of the note
  • body (text) : the HTML content of the note
  • plaintext (text, r/o) : the plaintext content of the note
  • creation date (date, r/o) : the creation date of the note
  • modification date (date, r/o) : the modification date of the note
  • password protected (boolean, r/o) : Is the note password protected?
  • shared (boolean, r/o) : Is the note shared?

I'm going to ignore the concept of attachments for the moment.

@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

My prototype showed that images embedded in notes come out in the HTML export as bas64 image URLs, which is neat.

@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

Converting AppleScript date strings to ISO format is hard!

https://forum.latenightsw.com/t/formatting-dates/841 has a recipe I'll try:

set todayISO to (todayDate as «class isot» as string)

Not clear to me how timezones work here. I'm going to ignore them for the moment.

@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

Before that conversion:

Monday, March 6, 2023 at 11:55:15 AM

After:

2023-03-06T11:55:15

simonw added a commit that referenced this issue Mar 9, 2023
@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

It doesn't have tests yet. I guess I'll need to mock subprocess to test this.

@simonw
Copy link
Collaborator Author

simonw commented Mar 9, 2023

OK, this works!

@simonw simonw closed this as completed Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant