Jump to content

Drill-Down Menus: Movie search (OMDb-API) & Alfred Repo


Recommended Posts

Hey,
 
I was experimenting with workflows that allowed "drilling down" into an result to provide more options, and here's what I came up with.
 
Firstly, a workflow that uses omdbapi.com to search for movies,
actioning a result shows you more information and actions.
 
movie.png
movie_django.png
movie_django_actors.png
Download: here or via AlfPT
 
 
As a second workflow using this I built an alternative client workflow to Tom Hunt's Alfred Workflow repository.
It has some performance improvements over the "official" AlfPT workflow, and a few extras like updating all workflows, uninstalling and opening workflow folder from within the workflow.
 
repo.png
repo_installed.png
repo_symbols.png

 

Download: here or via AlfPT

Link to comment
… I've been trying to accomplish much the same thing in Python but have only run up against difficulties. Ruby, though, is a totally foreign language to me—would I be a huge wang if I asked you to explain how it works?

 

 

… I'm with phyllistein on this one... Please enlighten the masses.

 

Sure, I'll explain it kind of conceptually what's going on and how it's implemented.

 

 

The three key factors here:

* Building paths using a separator character (➣) in the query

* Autocompletion to help build those paths

* Using ids in the path

 

Based on the current "path" in the query i decide what results to show.

So if nothing has been entered yet, in the case of the workflow repository one, i show the 4 main menu entries, each of which autocompletes to a defined Tag + the separator.

 

The next invocation of the script might be with the query "Browse ➣ ".

In that case I present all workflows, each of which autocompletes to "Browse ➣ (bundle id of workflow) ➣ "

I use the bundle id in the path because the next menu needs to know what you chose. For the movie workflow I use the IMDb-ID.

 

It would be prettier if I could use "Shutter Island ➣ " in the path, but sadly that isn't unique enough. It would also allow deleting the separator character with backspace and thereby going back to the previous menu and still get sensible results back (as the query would then be "Shutter Island" and not "tt1130884", the IMDb-ID).

But the query string is the only transfer mechanism we have to determine what item has been chosen.

 

For more information on how do the autocompletion check this out (basically, set valid="no" and autocomplete="your path" on an item)

 

 

 

 

So far for the concept.

 

On the implementation side i have the helper module AlfredFeedback.

 

In there I have helper functions "get_path" and "get_query".

get_query returns the very last part of the actual query-string given to the script

get_path returns the current path as an array

So for example "Installed ➣ com.linuslundahl.alfred.phpfunctionsapi ➣ open" would result in

get_path: ["Installed", "com.linuslundahl.alfred.phpfunctionsapi"]

get_query "open"

These help in deciding what items to present.

(In that example, I check if path is two segments long, which would mean I'm in the submenu for a workflow.

 The last segment is the bundle id of the chosen workflow and I show the "back", "update", "uninstall" and "open workflow folder" items.

 I apply get_query as a filter so that only the "open workflow folder" item remains)

 

Next I have a simple class called Item that just holds all the information for an feedback result item (title, subtitle, icon, arg, …)

 

Extending that I have a class called Menu.

These are the items that bring you to a submenu.

They have their autocomplete-attribute automatically set to the current path + the argument of that item + separator, and valid to "no".

 

Lastly I have the class Feedback, which gathers Items (and Menus) with add_item and add_menu methods.

(I also have .fixed_order in there, which automatically gives the items an uid of timestamp + index in item list, thereby the items are always presented in the order they are specified)

(And .autofilter, which takes the query to filter the items before printing them out if set)

After that just print out the feedback.to_xml

 

 

As for allowing different kinds of action on an item:

I use argument-strings in the form of "(action):(parameter)". In the movie workflow I have a whole bunch of actions for showing an image, opening URLs, showing large text, ..

This argument-string is passed to an output-script and appropriate action is taken.

Link to comment

One suggestion for the Repo workflow, if I may:

 

It would be good for the "Install" list to have an "hide" option (maybe be "option-click" on the selection) for items we don't want to see any more. Might be a way to keep the list from blossoming to unwieldy levels. (Alfred 2's still in beta, and it's already impressively large! :huh: )

 

Edit: Sorry, just one more quick thing - is there anyway to specify the time before the workflow attempts to acquire new data rather than just relying on the cache? Personally, I don't see a need for a fresh check any more often than 2-3 hours.

Edited by CarlosNZ
Link to comment
One suggestion for the Repo workflow, if I may:

 

It would be good for the "Install" list to have an "hide" option (maybe be "option-click" on the selection) for items we don't want to see any more. Might be a way to keep the list from blossoming to unwieldy levels. (Alfred 2's still in beta, and it's already impressively large! :huh: )

 

Good suggestion!

 

Option-click doesn't work very well with this type of menu, as I can only set one modifier subtext for every item in the whole workflow, including the menus (eg. "Browse").

I could set it to "Alternative action", which I find too non-descriptive, and isn't even true for items that don't provide an alternative action.

 

Instead, the "hide" option is now available when drilling down into a workflow in "Browse" and "Installed".

I want to keep installing and updating quick, so I won't drill down on pressing enter when in those menus,

but I found something new: 

You can now press Tab to drill down into a workflow, even in the "Install" menu.

Hidden workflows can still be found in "Browse > Hidden"

 

Edit: Sorry, just one more quick thing - is there anyway to specify the time before the workflow attempts to acquire new data rather than just relying on the cache? Personally, I don't see a need for a fresh check any more often than 2-3 hours.

Yep, you can set the timeout in the config file here: ~/Library/Application Support/Alfred 2/Workflow Data/at.robhor.alfred.alfredrepo/config

In there, you'll find max_cache_age, set it to how many seconds you'd like, eg. 7200 for 2 hours

 

Updated workflow found in the usual places… AlfPT or in itself or via updated link in the original post

 

----

 

 

Based on a request I've added some rotten tomatoes data to the movies workflow:

 

meter.png

Link to comment

Great job on the Alfred Repo workflow. I just had one problem. When I ran it, following error occurred:

 

./lib.rb:91:in `installed_workflows': undefined method `[]' for nil:NilClass (NoMethodError)
	from ./lib.rb:90:in `each'
	from ./lib.rb:90:in `installed_workflows'
	from ./lib.rb:127
	from repo.rb:3:in `require'
	from repo.rb:3

 

Turns out one of my installed workflows' info.plist files was empty (0 KB). No idea how that happened (I doubt it's typical), just thought I'd let you know.

Link to comment
Great job on the Alfred Repo workflow. I just had one problem. When I ran it, following error occurred:

 

./lib.rb:91:in `installed_workflows': undefined method `[]' for nil:NilClass (NoMethodError)
	from ./lib.rb:90:in `each'
	from ./lib.rb:90:in `installed_workflows'
	from ./lib.rb:127
	from repo.rb:3:in `require'
	from repo.rb:3

 

Turns out one of my installed workflows' info.plist files was empty (0 KB). No idea how that happened (I doubt it's typical), just thought I'd let you know.

 

I wouldn't be so sure it's atypical—turned out that's why it wasn't working for me, too. It broke after I updated a YouTube workflow and the folder filled with corrupted data. Deleting the offending folder solved the problem.

Link to comment

Is it just me or has the latest Alfred beta messed this up somewhat? When I hit "Tab" on a workflow name, it used to drill down to provide options ("hide" etc.). Now the existing Alfred field (ie. "repo Install ➣" is just highlighted and nothing happens.

Link to comment
Great job on the Alfred Repo workflow. I just had one problem. When I ran it, following error occurred:

 

./lib.rb:91:in `installed_workflows': undefined method `[]' for nil:NilClass (NoMethodError)
	from ./lib.rb:90:in `each'
	from ./lib.rb:90:in `installed_workflows'
	from ./lib.rb:127
	from repo.rb:3:in `require'
	from repo.rb:3

 

Turns out one of my installed workflows' info.plist files was empty (0 KB). No idea how that happened (I doubt it's typical), just thought I'd let you know.

 

 

I wouldn't be so sure it's atypical—turned out that's why it wasn't working for me, too. It broke after I updated a YouTube workflow and the folder filled with corrupted data. Deleting the offending folder solved the problem.

 

Thanks, I updated the workflow to protect against that!

 

 

 

Is it just me or has the latest Alfred beta messed this up somewhat? When I hit "Tab" on a workflow name, it used to drill down to provide options ("hide" etc.). Now the existing Alfred field (ie. "repo Install ➣" is just highlighted and nothing happens.

 

Still works for me (on b94)

Link to comment
Still works for me (on b94)

Okay, that's interesting. I have "tab" as my key for actioning items in Alfred, rather than the default right-arrow. And so "tab" was now highlighting the text instead of drilling down in this workflow. However, if I change it to the default key, it works fine with tab. Still seems odd though; might mention it to Andrew and see what the intention of this changed "tab" behaviour is.

Link to comment
  • 2 weeks later...

When I try to use the movie workflow I get the following error in the console:

[ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=42 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 42.)"

 

The workflow isn't working at all. It feels like if I'm typing something with a result it falls back to the standard Alfred Google search:

 

Bildschirmfoto%202013-02-07%20um%2000.33

Bildschirmfoto%202013-02-07%20um%2000.33

I'm using b112.

Link to comment

When I try to use the movie workflow I get the following error in the console:

[ERROR] Script XML Parse Error occured Error Domain=NSXMLParserErrorDomain Code=42 "The operation couldn’t be completed. (NSXMLParserErrorDomain error 42.)"

 

The workflow isn't working at all. It feels like if I'm typing something with a result it falls back to the standard Alfred Google search:

 

Thanks, I've updated the workflow, should be fixed now!

Link to comment
  • 2 weeks later...

The drill-down is a great concept.

 

I’m playing with recent Finder items and I used the concept:

 

rec1.png

 

Selecting “Applications”, for example, will load a list of recent apps:

 

rec2.png

 

At this point you can search the app by typing something. However if you hit delete (backspace) once, removing the space after the arrow symbol, the workflow will go back to its initial list (first screenshot).

 

Initially I thought that I could only use “search” Alfred 2 script command. However, right now the search command will only highlight the text in an existing Alfred 2 window. I was expecting that I could use this command to overwrite the current Alfred 2 text.

 

Anyway, I still use the search command. However, after it the workflow pastes the keyword and the list is back to its initial state. All that using AppleScript. 

 

It would be smoother (code cleaner) if Alfred 2 “search” command would work the same way with or without its window showing. Anyway, this workaround does the job in a smooth way, without flickering.

 

Note: this workflow is still a work in progress, not ready for a public release.

Link to comment

The drill-down is a great concept.

 

I’m playing with recent Finder items and I used the concept:

 

rec1.png

 

Selecting “Applications”, for example, will load a list of recent apps:

 

rec2.png

 

At this point you can search the app by typing something. However if you hit delete (backspace) once, removing the space after the arrow symbol, the workflow will go back to its initial list (first screenshot).

 

Initially I thought that I could only use “search” Alfred 2 script command. However, right now the search command will only highlight the text in an existing Alfred 2 window. I was expecting that I could use this command to overwrite the current Alfred 2 text.

 

Anyway, I still use the search command. However, after it the workflow pastes the keyword and the list is back to its initial state. All that using AppleScript. 

 

It would be smoother (code cleaner) if Alfred 2 “search” command would work the same way with or without its window showing. Anyway, this workaround does the job in a smooth way, without flickering.

 

Note: this workflow is still a work in progress, not ready for a public release.

 

Looks good, looking forward to it  :)

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