aosaigh Posted December 2, 2019 Posted December 2, 2019 I'm trying to create a workflow that will make it easy for me to add new notes to predefined location ~/Notes. This folder has a number of subfolders like ~/Notes/Computer ~/Notes/Life etc. I want to be able to create, save and open a new file in Alfred within one of these subfolders (or just the root directory). For example 1. I enter keyword "new note" plus the file name e.g. "Shopping List" in the Alfred bar 2. The alfred bar then suggests a number of folders in the dropdown menu. I can select one (or none) of these 3. The file is saved to that location as "Shopping List.md" 4. The file is opened in my text editor I understand most of the steps except how to do 2. How can I have a substep that shows me the folders within ~/Notes and lets me select and feed that chocie into the next stage?
vitor Posted December 4, 2019 Posted December 4, 2019 Welcome @aosaigh, Do you want step 2 to show a predefined set of directories (fixed), or all directories inside of ~/Notes (dynamic, changes depending on what exists)? Both are doable, but the former is simpler and doesn’t require programming. We can help you with either.
aosaigh Posted December 5, 2019 Author Posted December 5, 2019 I would like it show a dynamic list of all directories of depth=1 in the ~/Notes directory. I don't mind programming, I just wasn't sure how to go about it. I assume via a script so?
vitor Posted December 5, 2019 Posted December 5, 2019 In Ruby, you’d do this: require 'json' require 'pathname' script_filter_items = [] Pathname.new(ENV['HOME']) .join('Notes') .children .select(&:directory?) .each { |path| script_filter_items.push(title: path.basename, arg: path) } puts({ items: script_filter_items }.to_json) You can use that code as-is in a Script Filter (with Language set to /usr/bin/ruby) between your other steps in Alfred.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now