Jump to content

Newbie Python Script Filter

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")




Share this post

Link to post

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.

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.

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