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.
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.
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.
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.
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
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 showid “x-coredata://96A8340E-269E-47DA-816F-982FD342B9A1/ICNote/p33940” to location specifier
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.
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:
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.
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 showid “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?