Hazel with Apple Notes Help

Hi all

Looking for some help with Hazel from those far more advanced than myself!

At present I have a number of rules set up for various things that if a file comes in to downloads (usually a pdf) with certain text etc this is converted and copied to Evernote in a new note.

I have fallen out of love with Evernote due to the app responsiveness, I don’t have a large database, clean it out regularly but it is soooooooooo slow on iOS I can’t bear it.

So I looked at alternatives with a view to making the move before my premium is up. Apple notes actually fits what I want pretty well in the main and most importantly its quick and accessible.

It has however left me with a problem, I want to set up similar rules to add a PDF to a note, a new note is fine, I don’t mind periodically tidying up within the app, but I cannot find a way to add a file. I did find someone in the Noodlesoft forum who had done similar but I can’t get the script to work.

https://www.noodlesoft.com/forums/viewtopic.php?f=3&t=7373&p=28774&hilit=notes#p28774

Can anyone help or provide a script they use?

Thanks!

Here is a very simple script that you can build from.

tell application "Notes"
 	tell account "iCloud"
 		set newNote to make new note at folder "Notes" with properties {name:"Test", body:"You can add text here"}
 		make new attachment at newNote with data theFile
 		show newNote
 	end tell
end tell

You’ll need to update the account, if not using iCloud and will need to update the folder within which you want to save these notes.

I hope this helps — jay

4 Likes

That’s perfect! Thank you very much for your quick response.

Just wanted to say thanks again, managed to check it properly this morning and works perfectly! I really wish I could understand code better! I can read what you have written but wouldn’t have had a clue how to know what to put to make that work.

@Ethan9482, my pleasure. My advice… read, borrow from others, experiment and have fun. Google is your friend!

In this case (AppleScript), use Script Editor to experiment and test code. Far easier to play in that environment as you debug than to code directly to Hazel.

Once your script is working in Script Editor, you can adopt for use in Hazel (or Alfred or Keyboard Maestro…)

Here are a few references for learning more about AppleScript. I trust others here have other suggestions.

Sal Soghoian’s book is excellent. Dated, but still relevant

His website is also a great resource

Doug’s AppleScripts for iTunes is a fun place to poke around

While it has been some time since I’ve lurked there, Veritrope’s site had some good example scripts to use with Evernote

Hope some of these help you on your journey. — jay

Thanks I’ll take a look at these, think it’s just learning the specific terminology, I get the principles of what’s going on - just need to learn the words and start to embed piecing it together.

Learning the syntax of any programming language is (for most people) a matter of trial, error and repetition. I’ve been using python pretty heavily for a couple years now, and there are many patterns I use infrequently enough that I still need to look up (google) how to use them. Until I’ve typed it out a dozen times or so in real-world situations, I can’t count on remembering it.

To that end, one thing that has helped me, going back to my first forays into AppleScript two decades ago or more: When you find an example you can adapt to your own use, make yourself type it out. It’s slower, and you might make typos — but you’ll have to process every detail yourself, at least on a superficial level.

2 Likes

How do I make the “name” of the note the same as the file name?

Try this

tell application "Notes"
	tell account "iCloud"
        set theFileName to name of (info for theFile)
    	set newNote to make new note at folder "Notes" with properties {name:theFileName, body:"You can add text here"}
    	make new attachment at newNote with data theFile
    	show newNote
	end tell
end tell
1 Like

Hi there.
Two things:

  1. How can I move the file in a subfolder like “private/bills”
    2 I get an error, but I don’t get what it means:
    show id “x-coredata://96A8340E-269E-47DA-816F-982FD342B9A1/ICNote/p33940” kann nicht in Typ location specifier umgewandelt werden." number -1700 from show id “x-coredata://96A8340E-269E-47DA-816F-982FD342B9A1/ICNote/p33940” to location specifier

Thank you!

I think you can simply use the nested folder name in the “at folder” action. Eg:
set newNote to make new note at folder “Bills” with properties...

This works for me.

I can’t explain the error. See this post for maybe a related issue. I have not been able to resolve the issue I describe in the linked post. I’m still on Mojave and this script is still working for me.

1 Like

But what if there are two Bills folders in separate folders (e.g. private and work)?

Hey,
I’ve learned a bit since the last time.
I can address subfolders like this:
make new note at folder “Bills” of folder “private” with …

And I have to add to the make attachment line this:
… as POSIX file
Now it makes a note in the right folder with the attachment! Yeah!

But I have two more things, I want to achieve:

  1. I’d love to have the name/title of the note formatted as “title”. It should work with html-code like < h1 > title < /h1 >. But I don’t know how to aggregate the name and the html-code.
  2. The pdf in the note always has a huge empty space before it (see in the picture). How can I get rid of it?
    Thank you!

I’m trying to build a script that opens a pre-existing note. That’s it. Here’s what I have so far based on what I read in this thread:

tell application "Notes"
    tell account "On My Mac"
	    set newNote to make new note at folder "XYZ" with properties {name:"Test", body:"body text"}
	    show newNote -- this is the text that gets highlighted when the error occurs
    end tell
end tell

When I run it DOES create the note, however it doesn’t open the notes application and display the note. Instead, I get this error:

error “Notes got an error: Can’t make show id “x-coredata://95ABF30B-037A-471B-81DD-42ACC847D91B/ICNote/p2938” into type specifier.” number -1700 from show id “x-coredata://95ABF30B-037A-471B-81DD-42ACC847D91B/ICNote/p2938” to specifier

I would also like to open a pre-existing note rather than creating a new one, as I said before. How do I do this?

@jayelevy @Ethan9482