Hazel with Apple Notes Help

#1

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!

#2

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

3 Likes
#3

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

#4

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.

#5

@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

#6

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.

#7

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
#8

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

#9

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