Jump to content

Offline Unit Conversion Workflow

Recommended Posts

Critical update to v3.1 on 2017-11-02 (Yahoo! Finance API is dead)


Alfred-Convert v3

Yet another conversion workflow.


Main features:

  • Works offline, so super fast (occasional web access required to update exchange rates)
  • Many hundreds of units supported
  • 1000+ currencies supported, including cryptocurrencies
  • Custom, user-defined units 
  • Auto-updates






Download from GitHub.



The syntax is simple: the quantity, the unit you want to convert from then the unit you want to convert to. For example:

  • conv 128 mph km
  • conv 72in cm
  • conv 100psi bar
  • conv 20.5 m/s mph


Please see the README on GitHub for full instructions.


Supported units

Currently, Alfred-Convert supports all the units understood by the underlying Pint library plus a handful of additional units and 1000+ currencies. You can see a list of the supported currencies on the GitHub page.


Adding custom units


You can also add your own custom units. Use convinfo to open the unit definition file and the documentation describing how the definition format.

If you have a unit you think should be included by default, please create a corresponding GitHub issue or ask in this thread.

Edited by deanishe
Fix link to list of supported units
Link to comment
  • 5 months later...

I'm trying to learn your python workflow library and decided to try convert as a tutorial. However, if I write "conv x" in Alfred, it always goes to the fallback search (Google etc.). If I try to run the python script convert.py in Terminal, I get


python convert.py 200m/s mph
09:41:50 convert.py:100 DEBUG    query : 200m/s
09:41:50 background.py:215 DEBUG    Calling [u'/usr/bin/python', '/Users/myusername/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.417268A9-C3A4-4777-B247-D481035658FF/workflow/background.pyc', u'update'] ...
RuntimeError: Bad magic number in .pyc file
09:41:50 background.py:218 ERROR    Failed to call task in background
09:41:50 convert.py:57 DEBUG    quantity : 200.0 tail : m/s
09:41:50 convert.py:135 CRITICAL Invalid query : No destination unit specified
<?xml version="1.0" encoding="utf-8"?>
<items><item valid="no"><title>No destination unit specified</title><subtitle>For example: 2.5cm in  |  178lb kg  |  200m/s mph</subtitle><icon>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns</icon></item></items>09:41:50 convert.py:153 DEBUG    finished
So something happens in background.py and then it doesn't parse the second units correctly.
(But I'm actually more interested in understanding why Alfred doesn't tell an error occured but fell back to Google instead, since that happens also when I try to write something using the workflow library myself.)
Link to comment

background.py is failing because Python's trying to run the compiled version, background.pyc, but it was created by a different version of Python to the one you're running it with. Deleting all the .pyc files will solve that. This is unrelated to the parsing issue.
The reason it isn't working from the command line is that the script takes only one argument. You need to run python "200m/s mph" (note the quotation marks) to run it in Terminal.

Hard to say exactly what's happening wrt error messages in Alfred. What does Alfred's debugger show when you run the script?


There a fair bit of documentation for my library, which might be helpful.

Link to comment

Right, of course, I should've figured that out from the script in conv. Thanks!


The problem with running the script from within Alfred was due to /usr/bin/python pointing to python 2.5 while in Terminal python pointed to 2.7 from python.org. I changed the default version and now it works as it should. Thanks!

Link to comment
  • 4 months later...
  • 10 months later...

Yeah, it's a bug. Thanks for finding it!
Pint knows about cups, but the abbreviation for the Cuban peso is "CUP", and that's overriding the definition of cup as a measure of volume.
The error you're getting is because the workflow can't convert pesos to cubic centimetres…
I'll figure out a permanent solution for the next release within the next day or two.
As a temporary workaround, and assuming you don't need to work with Cuban pesos right now, you could try this:

  • Right-click on the workflow in Alfred Preferences and choose "Show in Finder"
  • Open the currencies.json file (but NOT with TextEdit!)
  • Delete the line that says "CUP": "Cuba Peso", (should be line 35)
  • Open Alfred and enter conv workflow:delcache to clear the currency cache (which may still contain Cuban Pesos)

Now "cup" should resolve to half a pint, and not Cuban pesos, so your conversion should work.

Link to comment
  • 2 weeks later...

I'm having trouble getting Convert to work. Anything I type (including the examples in the OP) just give the please wait subtext ("Convertifying...").


I've tried opening the debug window on the script, but nothing appears in the window. Other workflows I have installed work fine, including in debug - but none of them use python as far as I can tell. So I installed Searchio and it has the same problem.


When I go to the workflow directory and execute the script manually, it works fine.


Am I doing something stupid?

Link to comment

Okay, that's pretty weird. I cant imagine what "stupid" thing you might be doing.

First, we need to figure out if it's a problem with the workflow, the workflow library or your system.

Which version of OS X are you using?

Do any other Python workflows work that aren't written by me or based on my Alfred-Workflow library?

Could you try running the script manually from the workflow directory using /usr/bin/python (instead of just python)?

Link to comment

OS X 10.11.1


Relative Dates and Searchio stick on the please wait subtest.

Resolve URL displays invalid URL regardless of what is input.

Netloc says the current network is active; I'm not sure exactly what it's supposed to do, so that one may be working.


The python in my path is /usr/local/bin/python, which is version 2.6.4. Running convert.py manually using that fails. But the workflow specifies /usr/bin/python, which is version 2.7.10. Running that one manually returns XML with the correct answer (between a ton of DEBUG lines).



Link to comment
I'm at a bit of a loss, to be honest. My workflows usually explicitly specify /usr/bin/python, and you say they work with that Python when run from a shell…
I'm fairly certain that it's an issue with your system, rather than the workflow(s)/library, simply because nobody's had this problem before.
Is there anything in the workflows' log files (use <keyword> workflow:openlog in Alfred)?
Is there anything in the syslog in Console.app?
Have you messed around with your launchd/system environment?


Have you tried rebooting and/or repair permissions?
Edited by deanishe
Link to comment

Looks like you're right, it was a problem with my system.


I ran Disk Utility's First Aid (no more repair permissions as of El Capitan), no problems found.


Rebooted and tried Convert again, this time it immediately asked me to choose the Update action. I did, and it's working fine now. Thanks for the help!

Link to comment
  • 2 weeks later...
  • 2 months later...
  • 2 weeks later...
On 03/10/2017 at 6:57 PM, ErfahrungenCOM said:

hi deanishe, great addon. little problem with this converting euro to php (philippine peso), example:


conv 11 eur php


can you help out please?



Screenshot 2017-10-04 um 00.56.24.png


Sorry, I forgot to reply to your message. Use "PHP", not "php". Lowercase currencies only work as long as they don't conflict with built-in units.


As far as pint (the library that does all the converting) is concerned, p is the prefix for "pico" and hp is "horsepower", so "php" means "picohorsepower".

Link to comment
On 7/16/2017 at 11:24 AM, deanishe said:

Big update for version 3.


  • Option to exclude units when copying
  • Add per-dimensionality defaults
  • Option to specify thousands separator
  • Option to specify custom decimal separator
  • Add cryptocurrencies
  • Update Alfred-Workflow
  • Update Pint


Deanishe, sorry for hijacking the thread for a simple question. But what versioning criteria do you use to release a new major version?


I have read about SemVer that a new major version should come out when "any backwards incompatible changes are introduced to the public API". What can this mean in terms of an Alfred Workflow? Would it be the case of a new version for Alfred 3 that becomes incompatible with Alfred 2? Can I release a new major version just because of significant new features?

Link to comment
1 hour ago, xilopaint said:

any backwards incompatible changes are introduced to the public API". What can this mean in terms of an Alfred Workflow?


I don’t think semver is particularly relevant: workflows don’t usually have a public API.


1 hour ago, xilopaint said:

Can I release a new major version just because of significant new features?


Sure. You can increment it on every release if you want. Google Chrome’s on version 64 already.


As a rule, new major versions tend to be synonymous with paid upgrades, which isn’t relevant to free software.


If your workflow is associated with an app, you might use the same major version as the app for workflow versions that work with that app version.


Otherwise, I don’t think it matters much as long as the version numbers always go up…


I tend to go with “significant rewrite/new features = new major version”, but only because that’s what I know from most apps. I haven’t actually tried to develop a concrete concept for versioning. 

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