Jump to content

[SOLVED] How to use two variables for File Filters in Alfred ?


Recommended Posts

I have defined two environment variables and used them to get the variables.

 

For example:

 

environment variable: fifa = 6/14/2018    and python script gives dfifa = 30

environment variable: cmu =  6/16/2018 and python script gives dcmu = 32

 

Now, When we use {var:dfifa} and {var:dcmu} only one variable works.

 

The workflow is shared in github.

 

How can we fix the problem ? Thanks.

Edited by Bhishan
Link to comment

Firstly, I'm moving this topic to Workflow Help & Questions.

 

You need to run the scripts one after another, not in parallel:

 

image.png.b1b0831fbe42d0db83ec511d12f60976.png

 

If you run them in parallel, they don't complete at the same time. One of the paths will activate the List Filter before the other has finished, which is why only one variable is set.

 

It would make more sense to just have a single script (seeing as they're basically duplicates) that sets multiple variables.

 

Edited by deanishe
Link to comment

 

 

@deanishe  I would love to use single script

But the problem is two values are combined into single variable and they can not be used separately.

 

Here is the python script to print two numbers: 

from __future__ import with_statement, print_function, division
import sys
import os
import datetime
date_format = "%m/%d/%Y"


# Using variables
cmu = os.getenv('fifa')


# Calulating days difference
today_str = datetime.date.today().strftime(date_format)
today = datetime.datetime.strptime(today_str, date_format)

someday = datetime.datetime.strptime(cmu, date_format)
days_diff = abs((someday - today).days)


# print will give output
print('Days Until FIFA:', days_diff)

If I use:

 

print(30,40) # Just for practice

It will give {query} = 30,40  and How can we use 30 and 40 separately in File Action ?

days.png

Edited by Bhishan
Link to comment

@deanishe  Thanks for the reference.

 

That's a great article, but unfortunately, there is no example workflow to execute the theory explained.

 

Feature Request: If there are some simple example workflow it would be great and a lot of new users will benefit from them.

 

I tried to follow exactly the instruction and printed given format in python, but to no avail:

 

import sys


output = """
{"alfredworkflow:" {
"arg": "https://www.google.com",
"variables": {"browser": "Google Chrome"}}}
"""
print(output.lstrip())

 

In bash script:

echo $browser > ~/hello.txt

 

It did not print the google chrome in  ~/hello.txt.

 

I have uploaded the workflow here

Edited by Bhishan
Link to comment
32 minutes ago, Bhishan said:

printed given format in python

 

You don't create JSON in Python using strings. You don't do it in any language. You use a proper JSON library, or you will mess it up:

 

import json
import sys

browser = 'Google Chrome'
arg = 'https://www.google.com'

data = {'arg': arg, 'variables': {'browser': browser}}

json.dump({'alfredworkflow': data}, sys.stdout)

 

Also, use Alfred's debugger. It told you precisely what was wrong with your script.

Edited by deanishe
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...