Jump to content
godbout

Loading text for items returned by script?

Recommended Posts

I'm new to writing workflows. I'm having a trigger that launches a php script, I have a loading text for that trigger, but the items returned by my script will also take time when the user chooses them, so I'd like to change also the subtitle once it's chosen, so that the user knows something is being worked on after his choice. Is there a way? Or am I missing something in how the script filters work?

 

I am not launching another script once the user selects an option, and I don't post anything (just grabbing data from an API, and injecting the results in Alfred items at the final step).

 

Thanks

Share this post


Link to post

The question isn't very clear. How can an item take time after the user chooses it if you aren't launching another script?

 

Could you post your workflow somewhere, so we can see what you're doing?

Share this post


Link to post

I agree, not very clear, because I'm getting lost and confused in all this. At first I tried to use a "script filter" that outputs to a "run script". I was expecting to be able to send back options for the user to choose from the "run script" but I wasn't able to make that work (maybe this is not how it is supposed to work?) so I ended up with just a "script filter" trying to handle all the user selections. I'm having 2 issues, one is this "loading text" thing in items sent back to Alfred as options, another one is that I can't get the "arg" of the items in the script, all I get is what is typed in the main input, not what the user chose as a selection. That is why if you are able to test the workflow, you will see that when the user chooses a "project", I have to send the "project ID" in the main input (through "autocomplete"), I cannot use the name because this is what is passed to the script, not the "arg" of what has been selected, which always contains the "project ID". 

 

Here's the workflow: http://sleeplessmind.info/about/Harvest - COPY.alfredworkflow

The part I'm struggling with is at the bottom, "hv report". 

 

Thanks for the help :)

Edited by godbout

Share this post


Link to post

I can't actually run the workflow because I don't have a harvest account (never heard of it, tbh).

 

But why can't you connect your first Script Filter to another Script Filter to perform the second stage? Same goes for your settings.

 

It looks like you've copied David's multi-step example, but that was a workaround for Alfred 2, which doesn't support connecting multiple Script Filters together.

 

If you really must use a single Script Filter for two stages, the usual way to do that is to use a delimiter in your query:

 

OmsK8Gw.gif

 

The Script Filter checks if the delimiter is present in the query. If not, it shows the list of smart folders (or projects in your case). Each item has valid=false and autocomplete set to the name (or id) of the folder plus the delimiter (so ↩ or ⇥ autocompletes the name/id and calls the Script Filter again with it).

 

If the delimiter is in the query, the Script Filter loads the folder (project) specified by the first half of the query, filters its contents by the second half of the query, and shows the results in Alfred.

 

Workflow and source code are here.

 

Another thing if you're planning on distributing the workflow:

 

You're using the wrong data directory. Your relative path works for folks who don't sync their workflows, but will be in the wrong place for those who do (the workflow will be in Dropbox or some other folder, not ~/Library/Application Support/Alfred 3). Get the correct path from the alfred_workflow_data environment variable, i.e. $dir = getenv('alfred_workflow_data');

Share this post


Link to post

Thanks for the detailed answer. I'll have a look at your example workflow.

 

Actually I am (was) building on top of an existing—and old—workflow so most of the things were done by someone else (workflow data, script filters, etc...). I was trying to update it to Alfred 3 and I've only added the "Report" part. I've decided to start a new one from scratch, and wow, I didn't think (understand before?) of a script filter connected to another script filter. I will have a look on that, thank you, I think that will open my options quite widely.

 

From what I had understood until now—and please correct me if I'm wrong—the script filter is for the results that Alfred will show the user, and then with the results who are valid=true, when the user selects, the next action in the chain will be performed. If I run a normal (not filter) script as a result , there's no way that this script gives back results to Alfred, is that correct? I can call Alfred back with external triggers, but it shouldn't be used to filter according to what the user selected, right?

 

I hope I'm not too confusing. To be honest I'm quite ok with triggering some scripts that call APIs and all, I'm just struggling with handling Alfred, with the results, the selections, going up and down "menus", etc... I've read the workflow part on the website but I still seem to not getting it, and the examples from Alfred seem to never match what I'm trying to do. I don't know exactly how broad are the capabilities of the workflow. Maybe what I'm trying to do is not possible? Which basically is allowing the user to select options once they type a keyword (options from the workflow will be different according to the status of the workflow, like if the user hasn't setup yet, etc...), but also to go back up if needed, all with a clean input in Alfred. I see workflows with clean input but you can't go back up, and I see workflows where you can go back up but with not clean input (like the one you showed in your answer, with the delimiters in the query).

 

If you don't get what I mean or you don't wanna answer verbosely it's fine. Writing the post helps my brain clarifies all that. It is so enigmatic to me currently that I feel like I don't even know how to write in English anymore. Probably after checking your workflow and playing a bit more I'll be less confused. If you think about some links that might be relevant, please feel free to share. Sorry again if this seems a mess, and thanks a lot for your help! It is indeed useful and valued. :)

 

Edited by godbout

Share this post


Link to post
43 minutes ago, godbout said:

Maybe what I'm trying to do is not possible? Which basically is allowing the user to select options once they type a keyword (options from the workflow will be different according to the status of the workflow, like if the user hasn't setup yet, etc...), but also to go back up if needed, all with a clean input in Alfred. I see workflows with clean input but you can't go back up, and I see workflows where you can go back up but with not clean input (like the one you showed in your answer, with the delimiters in the query).

 

Those are your two options. If you want to be able to go back up, you either need the multi-level query or you have to add an extra "Back" or "Up" item to your results and handle navigating that way.

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