惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Simply Explained

Converting a Tuya Thermostat to ESPHome Bringing Foam Monsters to Life: How I Wrote and Illustrated a Children's Book Using AI How I Built an NFC Movie Library for my Kids Analyzing Link Rot in My Newsletter (After 31 Editions) Year in review: 2022 Smart lights behind a wall switch (Shelly, Z-Wave, ESPHome) Serverless Anagram Solver with Cloudflare R2 and Pages Integrate Home Assistant with Apple Reminders How WebP Images Reduced My Bandwidth Usage by 50% Tracking gas usage with ESPHome, Home Assistant, and TCRT5000 My Sixth Year as YouTube Creator (statistics + retrospective) EZStore: a tiny serverless datastore for IoT data (DynamoDB + Lambda) ESP-IDF: Storing AWS IoT certificates in the NVS partition (for OTA) How to securely access your home network with Cloudflare Tunnel and WARP I Built a CO2 Sensor and It Terrifies Me Filtering spam on YouTube with TensorFlow & AI Building a killer NAS with an old Rackable Server How I Structure My ESPHome Config Files Howto Virtualize Unraid on a Proxmox host MAX17043: Battery Monitoring Done Right (Arduino & ESP32) Preventing Cumulative Layout Shifts with lazy loaded images (Eleventy + markdown-it) Migrating This Blog From Jekyll to Eleventy Good Home Automation Should be Boring ESP32 Cam: cropping images on device Retrospective: My Fifth Year on YouTube Secure Home Assistant Access with Cloudflare and Ubiquiti Dream Machine Shelly 2.5 + ESPHome: potential fire hazard + fix Impact of Adblockers on Google Analytics (vs. Plausible) Shelly 2.5: Flash ESPHome Over The Air! Tuya IR Hub: control Daikin AC (Home Assistant + ESPHome) Building Air Quality Sensor: Luftdaten + Home Assistant HEIC to JPG: Build a Quick Action with Automator Make Your Garage Door Opener Smart: Shelly 1, ESPHome and Home Assistant Static webhosting benchmark: AWS, Google, Firebase, Netlify, GitHub & Cloudflare Why I don't take sponsorships Monitoring my 3D printer with a Pi Zero, Home Assistant and TinyCore Linux ESP32: Keep WiFi connection alive with a FreeRTOS task Home Energy Monitor: V2 Retrospective: 4 years on YouTube
How I Use Alfred to Search My Obsidian Notes Faster (with Spotlight!)
Xavier Decuy · 2023-03-22 · via Simply Explained

In this post, I’ll show you how I integrated Obsidian into Alfred so I can search my vault from anywhere on my Mac. I just open Alfred, type “note” followed by my query, and see my search results. Hit enter and the correct note opens in Obsidian. Easy and quick!

Note: the instructions below require an Alfred Powerpack.

Here's a screenshot of the Workflow in action:

Just text files

An Obsidian vault is a folder on your local hard drive with text files inside. You can search through it using any tool that can search files on disk.

My goal is simple: create an Alfred Workflow that allows me to search through my notes from anywhere.

The first question is: how can I search through my notes? I initially wanted to use grep, but that's inefficient as it doesn't build an index. Then I realized every Mac has a great search engine built-in: Spotlight!

Spotlight's command-line interface

Much to my surprise, I found Spotlight has a command-line interface. You can search inside any folder by using the following command:

mdfind "search query" -onlyin /path/to/obsidian-vault

Creating a Workflow in Alfred

Armed with this knowledge, I created a new workflow in Alfred. I added a script filter and configured it as follows:

  1. Set the keyword to “note” (or anything else you prefer).
  2. Set argument to required. You need to enter a query before the script should run.
  3. Set the programming language to Python 3 (must be installed first).
  4. Deselect the option "Alfred filters results". Spotlight does this for us. Alfred should only show the results and don't mess with it.
  5. Use the following Python script:
"""Use Spotlight to search an Obsidian vault and present results to Alfred"""

import subprocess
import json
import sys
import os.path

MAX_RESULTS = 20
VAULT_PATH = "/path/to/your/obsidian-vault"

QUERY = sys.argv[1]
COMMAND = ['mdfind', QUERY, '-onlyin', VAULT_PATH]

with subprocess.Popen(COMMAND, stdout=subprocess.PIPE, text=True) as proc:
    results = []
    count = 0
    for path in iter(proc.stdout.readline, ''):
        count += 1
        if not path or count == MAX_RESULTS:
            break

        results.append({
            "title": os.path.basename(path),
            "subtitle": path.replace(VAULT_PATH, ""),
            "arg": path.replace("\n", ""),
            "type": "file:skipcheck"
        })

    json_object = json.dumps({"items": results})
    print(json_object)  # Alfred will pick this up

The Python script uses mdfind to search your notes and gives the results to Alfred in a specific JSON format.

At this point, Alfred will show search results, but nothing will happen if you click on a result. To fix that, connect an “Open URL” action to the script filter:

The "Open URL" is configured to take the highlighted result and pass it to Obsidian:

Now try it out! Open Alfred, type "note", followed by your query and watch the results appear. Pick any result, hit enter, and Obsidian should open the correct note.

Why use Spotlight + Alfred?

There’re a couple of reasons I prefer this setup over the built-in quick switcher or search feature of Obsidian:

  • Spotlight is fast and already indexes your notes.
  • Search ranking is better compared to Obsidian. I also feel like it has better fuzzy matching.
  • I'm a heavy Alfred user and have countless of workflows to speed up my work. Adding Obsidian saves a bit more time.
  • Alfred can be triggered anywhere you are. No need to switch to Obsidian first, before you can search.

One limitation of Spotlight is that we can't show a snippet of the note. But I found that to be a non-issue as Spotlight is quite accurate and my filenames are descriptive enough.

Download the Workflow

Want to use it yourself but don't want to set everything up? Download the workflow here.

Happy note taking!