Jump to content
FroZen_X

Easy way to make suggestion list?

Recommended Posts

Hey,

 

is there an easy way to make a suggestion list in Alfred. Like for a query i would like to make a autofill of a fixed list used for a URL search.

For instance: "test " would show you a list of suggestions to fill in to use for a custom search on a website.

 

Maybe someone knows a easy way, thanks.

 

Cheers,

 

Frozen

 

 

 

 

Share this post


Link to post

Your description isn't very clear.

 

What exactly do you want to enter into Alfred and what do you expect it to show as a result?

 

What should you be able to do with the results?

 

Im Notfall geht auch Deutsch.

Edited by deanishe

Share this post


Link to post

Well, its basically for League of Legends, but i wanna use it for other stuff too.

Currently i have a workflow for the website champion.gg. Its just another query search on the

website like this: http://champion.gg/champion/{query}

 

I have the Problem that i have to type the full champion name over and over. It would be more convenient 

to simply show a fixed champion list of which i can choose or it autocompletes via "tab".

 

Und woher weißt du das ich deutscher bin ^^ Denk mal, da meine Beschreibung schlecht war.

Englisch ist aber besser, damit auch andere davon profitieren können.

Share this post


Link to post

Well, its basically for League of Legends, but i wanna use it for other stuff too.

Currently i have a workflow for the website champion.gg. Its just another query search on the

website like this: http://champion.gg/champion/{query}

 

I have the Problem that i have to type the full champion name over and over. It would be more convenient 

to simply show a fixed champion list of which i can choose or it autocompletes via "tab".

So you want Alfred to show/autocomplete a list of champion names?

Is there anywhere to get this list? Would it be okay to hardcode the list in the workflow?

 

Und woher weißt du das ich deutscher bin ^^ Denk mal, da meine Beschreibung schlecht war.

Englisch ist aber besser, damit auch andere davon profitieren können.

I'm a moderator and we can see users' email addresses. web.de is only used by Germans  :)

Edited by deanishe

Share this post


Link to post

Yes i want alfred to show/autocomplete. I could make the list myself and it would be hardcoded yeah(the list doesn't change often).

If you could show me how, then i could do the rest myself as i want to learn :) 

Running scripts and everything is no problem, just this damn show/autocomplete.

 

And ah ok xD didn't know that. 

Share this post


Link to post

Script Filters aren't that difficult if you use a library to generate the XML.

 

If you use Alfred-Workflow, it can also filter the results for you based on your query, which can be a bit complex to do.

 

With a more concrete specification, I could give you some code.

Share this post


Link to post

I just checked the tutorial out for a moment gonna look into it more tomorrow. 

I guess you can add items via:

 

wf.add_item(title=post['description'],
                     subtitle=post['href'],
                     icon=ICON_WEB)

and then return via:

wf.send_feedback()
 
From there on actions can be taken like fill and send the query to a URL.
The list would look something like this:
Aatrox;Ahri;Akali;Alistar;Amumu etc.
 
Like in the Pinboard tutorial listed under each other.
Is there a way i can parse through a external list like a txt file ? 
Then using a for loop like in the Pinboard workflow would do that job i guess ?
Edited by FroZen_X

Share this post


Link to post

Ok so via this:

# encoding: utf-8

import sys
from workflow import Workflow, ICON_WEB, web

def main(wf):

     wf.add_item(title=u'Aatrox',arg='Aatrox',valid=True,)
     

     # Send the results to Alfred as XML
     wf.send_feedback()


if __name__ == u"__main__":
     wf = Workflow()
     sys.exit(wf.run(main))

i can add my champions and set an action to it for the URL. 
Now is there a way to parse easy from a textfile as looping through wf.add_item is 
way better. Having for every champ a wf.add_item would be impossible to overlook lol
 
Edit: Just saw that filtering would be good too like you said. Thought it already did that but i was wrong. 
And do you know why the normal textedit changes "'" all the time to "’" -.- it produces a fault for python....
Edited by FroZen_X

Share this post


Link to post

Got a step further. I can now read out of a text file like this:

# encoding: utf-8

import sys
from workflow import Workflow, ICON_WEB, web
inputfile = open('testnames.txt')



def main(wf):
 for line in inputfile:
  wf.add_item(title=line,arg=line.rstrip(),valid=True)


 # Send the results to Alfred as XML
 wf.send_feedback()


if __name__ == u"__main__":
     wf = Workflow()
     sys.exit(wf.run(main))

 
The text file looks like this:
 
Aatrox
Ahri
Akali
Alistar
Amumu
 
The combination with a URL works too. I just need to know now how to filter oO as it shows
me everything at once whatever i type :/ 
Thank you very much so far :)
Edited by FroZen_X

Share this post


Link to post

TextEdit does that because it's not meant for programming. Get a proper code editor. TextMate 2 is very good and entirely free.
 
Reading the names from a text file would be the best way. It'd look something like this: 

filepath = '/Users/me/Documents/champions.txt'
 
def get_champions():
    champions = []
    with open(filepath, 'rb') as fp:
        for line in fp:
            line = line.strip()
            if line:
                champions.append(line)
    return champions
 
def main(wf):
    for c in get_champions():
        wf.add_item(c, arg=c, uid=c, valid=True)
 
    wf.send_feedback()

Share this post


Link to post

When you post code, can you use the code button (<>)? It's almost impossible to read code without it, especially Python where the whitespace is meaningful.
 
Filtering looks something like this: 

def main(wf):
    # If you have /usr/bin/python script.py "{query}" in the Script box,
    # Alfred will *always* give you a query, it just might be an empty string.
    query = wf.args[0]
    
    champions = get_champions()
    if query:
        champions = wf.filter(query, champions, min_score=30)
 
    if not champions:
        wf.add_item('No matching champions', icon=ICON_WARNING)
 
    for c in champions:
        wf.add_item(c, ...)
 
 
    wf.send_feedback()

Share this post


Link to post

I just got it to work like this:

 # encoding: utf-8

import sys
from workflow import Workflow, ICON_WEB, web
inputfile = open('testnames.txt')

def main(wf):

 if len(wf.args):
      query = wf.args[0]
 else:
      query = None
 

 if query:
      buffer = wf.filter(query, inputfile)

 for line in buffer:
  wf.add_item(title=line,arg=line.rstrip(),valid=True)


 # Send the results to Alfred as XML
 wf.send_feedback()


if __name__ == u"__main__":
     wf = Workflow()
     sys.exit(wf.run(main))



Share this post


Link to post

Gonna get Textmate now as this is annoying, thanks for suggesting.

Thank you very much for your help, the tutorial is really good :)

 

I just struggled sometimes in python cause of the whitespaces yeah. I've rarely

done anything in Python.

 

I'm gonna add some of what you've just send i guess and will look into icons as 

adding champion Icons would be cool haha :D

 

Edit: I changed my posts now, so its readable :) thanks

Edited by FroZen_X

Share this post


Link to post

I added icons now  :D this is freaking awesome! Thanks again to deanishe :)

 

While it looks like you've already done a great job with this workflow, I think you'll both be interested to hear that there are a few new workflow objects in v3 that will help make this process easier.

 

There will be a simple list object that allows you to create your own fixed list and filter through the results - Sounds like this would be perfect for the workflow you've just made and would require no scripting at all if the list is fixed!

 

An alternative object will allow you to use a script to return a list of results, then use Alfred to filter the results from that point onwards.

 

We'll be sharing more details on new workflow objects soon! :)

 

Cheers,

Vero

Share this post


Link to post

That sounds pretty cool! I'm curios what we will see with v3 :)

In addition to deanishe's question would i like to know, if this includes different icons or only one?

Share this post


Link to post

Out of interest, what kinds of lists can you plug into v3?

 

Strictly text files, one line per item, or also things like TSV/CSV/XLS files?

 

For static lists, you won't even need to plug anything in like this, it's much simpler. There's a new "List Filter" input object, and the config sheet for this filter allows you to simply build a list of result items (with separate titles, subtitles, icons, arg etc) in the UI without any scripting.

 

The other option Vero mentions is the Script Filter which can now return the results once, then Alfred does the subsequent filtering of the results:

 

Script%20Filter%20Alfred%20filters.png

Share this post


Link to post

For static lists, you won't even need to plug anything in like this, it's much simpler. There's a new "List Filter" input object, and the config sheet for this filter allows you to simply build a list of result items (with separate titles, subtitles, icons, arg etc) in the UI without any scripting.

That sounds awesome for short, one-off lists, but not so much for larger datasets. Of the people I've helped build workflows to address this kind of use case, only one was using a list short enough to be reasonably entered into Alfred by hand. More often, there are scores of items and the datasets aren't entirely static, either.

Are the list data stored in a format/place that would lend itself to being auto-generated/updated by a script or other program?

 

The other option Vero mentions is the Script Filter which can now return the results once, then Alfred does the subsequent filtering of the results:

 

Script%20Filter%20Alfred%20filters.png

Massive feature for a lot of users, imo. That's the one feature Launchbar has that's a big win vs Alfred 2.

Personally, "with input as argv" piques my interest much more.

Share this post


Link to post

That sounds awesome for short, one-off lists, but not so much for larger datasets. Of the people I've helped build workflows to address this kind of use case, only one was using a list short enough to be reasonably entered into Alfred by hand. More often, there are scores of items and the datasets aren't entirely static, either.

Are the list data stored in a format/place that would lend itself to being auto-generated/updated by a script or other program?

 

 

This is exactly why I updated the Script Filter with the ability for Alfred to filter the returned results. This can load / transcode / generate the data from anywhere you like, and pass it back in a single shot for Alfred to subsequently filter.

Share this post


Link to post

So with respect to workflows like the one we built in this thread, the big difference in implementation versus Alfred 2 would be that I don't need the block that calls wf.filter()?
 
(In terms of actual usage, I'll be surprised if Alfred 3 can't comfortably handle 20+ times as many items as wf.filter() without a noticeable delay.)

Share this post


Link to post

That's correct, and in real terms, you should see a performance increase as Alfred only runs the script once and then has the data in memory for filtering with subsequent keypresses.

 

Essentially...

  • For simple static result lists, the new List Filter will be perfect. Requires no scripting and is easy to configure.
  • For more complex static result lists which may need to be dynamically created based on upstream variables / configuration, using the updated v3 Script Filter and passing back JSON representing the results, then Alfred filters is the way to go.
  • For full control over results and filtering, with the script being run as the user types, using the Script Filter as per v2 is best.

Cheers,

Andrew

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