vex Posted December 6, 2024 Posted December 6, 2024 Overview: I'm creating a workflow to extract all links (including x-devonthink-item:// deep links) from a Markdown file and display them in Alfred for selection. Despite extensive testing, the links do not appear in Alfred, although the script works perfectly in the terminal. Goal: • Input: Select a Markdown file via a File Filter in Alfred. • Output: Display all links in the file as individual Alfred items with actionable links. Setup: 1. File Filter: • Scope: Targets Markdown files in a specific folder. • Output: Passes the selected file path to the next step. 2. Run Script (Python 3): import sys import re import json from pathlib import Path def extract_links(file_path): try: content = Path(file_path).read_text() links = re.findall(r"(https?://[^\s]+|x-devonthink-item://[^\s]+)", content) return { "items": [ { "title": link, "subtitle": "Press Enter to open this link", "arg": link, "valid": True } for link in links ] } except Exception as e: return {"items": [{"title": "Error", "subtitle": str(e), "valid": False}]} if __name__ == "__main__": if len(sys.argv) > 1: file_path = sys.argv[1] print(json.dumps(extract_links(file_path))) else: print(json.dumps({ "items": [{"title": "No file specified", "subtitle": "Please select a valid file", "valid": False}] })) 3. Open URL or Copy to Clipboard: • Input: {query} from the script. • Expected to open the selected link or copy it to the clipboard. Issues Faced: • The workflow passes the file path from the File Filter to the Run Script. • The Python script correctly processes the file and outputs valid JSON when run in the terminal. • However, Alfred does not display the results as actionable items. Not at all, just disappears. What I've Tried: 1. Debugging the workflow in Alfred: • The Debugger confirms the file path is passed to the script. • No errors are displayed, but Alfred doesn't show any results. 2. Simplified the script to output hardcoded JSON: • Even hardcoded JSON fails to display in Alfred. 3. Confirmed the JSON structure meets Alfred's requirements:
vitor Posted December 6, 2024 Posted December 6, 2024 Welcome @vex, You’re using a Run Script Action. That’s just for running code and passing it to the next object. What you need is a Script Filter Input. vex 1
vex Posted December 6, 2024 Author Posted December 6, 2024 I feel dumb now hahaha. That was so easy. It is my first workflow tho. 🤷 Thank you so much, appreciate the help.
vitor Posted December 6, 2024 Posted December 6, 2024 It seems to otherwise be going well already, the other objects make sense where they are, looks like a good and useful first workflow. Keep it up, we’re here to help if you have more questions.
vex Posted December 6, 2024 Author Posted December 6, 2024 Actually I do have another question since we are here. Is there any way to have my index results show numerically? Have tried scripting but not quite successfully. Thank you
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