Jump to content

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?



Link to comment

In Ruby, you’d do this:

require 'json'
require 'pathname'

script_filter_items = []

  .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.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...