beet / alfred_noteplan_actions

Alfred workflow for handy Noteplan actions
38 stars 4 forks source link

Add support for NP folders #20

Closed jgclark closed 3 years ago

jgclark commented 4 years ago

I'm not quite sure when Eduard introduced folders into NP, or if I have them because of beta testing, but at least from v2.4.2 NP honours sub-folders in the NotePlan/Notes directory.

However, I'm pretty sure from my testing that these Alfred actions don't pick them up -- not unreasonably. In my scripts it's just been a one line change to look over sub-folders as well.

NB: From the beta testing at least, I see that there will be at least two special sub-folders: @Archive and @Trash. They appear without the @ symbol in special places in the sidebar. So I have (in advance of any documentation) used a file glob that ignores items in sub-folders with an @ prefix.

brokosz commented 4 years ago

@ are definitely new with the beta. Eduard recommended to me the other day to start using more folders with v3 to control the notes list (mine is... lengthy) so I expect to see more usage of them.

beet commented 4 years ago

Wow, I'm not across folders in NotePlan at all as I haven't tried any of the betas. Personally, I'm more into searching/tagging and linking pages together with wiki-links than using hierarchical directory structures, but a lot of people (most?) do work that way.

You're right, it would totally cause any notes nested within a sub-dir to not be picked up by this workflow, but it should be simple enough to load notes recursively with a small change to NotePlan::Base#for_each_note:

def for_each_note(&block)
  Dir.glob("#{notes_directory}/**/*.txt") do |filename|
    yield NotePlan::NoteFile.for(filename)
  end
end
jgclark commented 4 years ago

@beet, following my note in the original post on this issue, I believe the glob line will need to be more like:

Dir.glob("#{notes_directory}/{[!@]**/*,*}.txt") do |filename|

This is what I'm using in my own ruby scripts that support NotePlan.

jgclark commented 4 years ago

Oh, this is frustrating. I've tried replacing just that one line in (the full 0.7.0 release of) NotePlan::Base with your update and running it again. Now I get exactly the same extensive debug logging that I reported in #14, and it fails to find the extra notes. Ditto with my suggestion amendment. It feels like there's something that just breaks as soon as I tinker with your release, and so I've reverted. I hope it works better for you.

brokosz commented 4 years ago

Dir.glob("#{notes_directory}/*/.txt") do |filename|

So this works, but it fails on lib/note_plan/note_file.rb:

[09:50:01.519] NotePlan Actions[Script Filter] Queuing argument '(null)'
[09:50:01.866] NotePlan Actions[Script Filter] Script with argv '(null)' finished
[09:50:01.869] ERROR: NotePlan Actions[Script Filter] Code 1: /Users/brokosz/Dropbox/Mackup/alfred/Alfred.alfredpreferences/workflows/user.workflow.A89AA877-CF25-4DD5-9F50-17A38CF5ADB0/lib/note_plan/note_file.rb:30:in `module_eval': (eval):1: syntax error, unexpected tIVAR (SyntaxError)
NotePlan::NoteFiles::@Archive
                     ^~~~~~~~

NotePlan now has special character folders for Archive (@archive) and Trash (@trash).