anyboxhq / anybox-alfred-workflow

45 stars 3 forks source link

Search for files? #4

Closed yinan-c closed 6 months ago

yinan-c commented 1 year ago

Hi, it seems the workflow only search for links, is it possible to search for files as well?

francisfeng commented 1 year ago

It’s technically possible. But you will have to do it yourself as the app is still focusing on links.

https://github.com/anyboxhq/anybox-alfred-workflow/blob/5eb18cc5562137c916c73ce4bf4363ea442c42c6/src/search-links.py#L108

In the Python script of Search for links in Anybox action from Alfred, you can add a type parameter with value all. So the payload will be like:

  payload = {
      'q': q,
      'limit': 30,
      'type': 'all' # 'link' (default) | 'note' | 'image' | 'file' | 'all'
  }

With this change, you can search all types of content. If you need to show the file in Finder, you can continue to tweak the action with a few steps.

  1. Click the conditional object in workflow editor.
  2. Click the Add a new condition button.
  3. Select matches regex and paste the regex ^\/Users.*? in the value field.
  4. Connect the condition with a Reveal File in Finder action.
conditional object Alfred workflow action

If you don’t want to maintain a separate version of this workflow, you can copy the action and create a new workflow to just search for files.

yinan-c commented 1 year ago

Thank you very much! Following your guid, I got it working.

However the debug session shows following error message, do you know what might be the cause ? Is it relevant?

[02:26:13.989] ERROR: Anybox[Run Script] Traceback (most recent call last): File "/Users//Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/ , line 10, in 'http://127.0.0.1:6391/document/' + sys.argv[2], headers=headers, method='PUT') IndexError: list index out of range

yinan-c commented 1 year ago

This happens when I command + enter to reveal in Anybox, although successfully navigate to the file in anybox, there is an error message. (I guess it is not a big deal as long as it works.)

francisfeng commented 1 year ago

It’s not affecting any functionality. But if you want to remove the error, you can add a condition to make sure sys.argv has enough arguments.

import urllib.request
import sys
import os

api_key = os.getenv('api_key')

headers = {'x-api-key': api_key}

if len(sys.argv) >= 3:
    req = urllib.request.Request(
    'http://127.0.0.1:6391/document/' + sys.argv[2], headers=headers, method='PUT')
    urllib.request.urlopen(req)
yinan-c commented 1 year ago

Thanks, it is really helpful!