Jump to content

Newbie Python Script Filter


Guest

Recommended Posts

I'm trying to use a Script filter to show 16:9 and 4:3 dimensions from a typed width. I can get it to work my code editor, but not Alfred. Please help me with this workflow.

 

import sys
query = {query}

wide_ratio = (float(16 / 9))
wide_height = (int(query / wide_ratio))

trad_ratio = (float(4 / 3))
trad_height = (int(query / trad_ratio))

print (wide_ratio)
print (trad_ratio)
print (("16:9 ratio = ") + str(query) + str("w x ") + str(wide_height) + "h")
print (("4:3 ratio = ") + str(query) + str("w x ") + str(trad_height) + "h")

sys.stdout.write(query)
 

01.jpg

02.jpg

Link to comment

As a rule, you should upload your actual, non-working workflow for us to look at, not screenshots.

 

In this case, there is at least one very obvious error, though.

 

You can’t just print line of text to show results in Alfred. You have to print your results as JSON in a specific format or Alfred will ignore them. See the built-in example workflows.

 

Also, print and sys.stdout.write do the same thing (write to STDOUT).

 

You must not use them for anything but outputting Alfred’s JSON.

 

It also looks like you’ve been reading Python 3 tutorials. print isn’t a function in Python 2. You should put “from __future__ import print_function” at the very top of your script to make print work properly that way.

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