Jump to content
aosaigh

Create new file, choose directory and open in editor

Recommended Posts

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?

 

 

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...