Jump to content

Workflow: Units - convert currency length temperature weight and more


Recommended Posts

A better unit converter

 

0_5_inch_live2.gif

 

 

 Download V0.6

contact thijs@designandsuch.com for questions, bugs, ideas and such

 

try out the demo

 

 

 

 

There are more unit converters available. but i didn't like the lack of speed due to the feeds. Thus i redid one myself which calculates everything on your mac. It fetches new currency data once in a while.. that's the only time when a second delay might appear. And in my humble opinion it's already better than all other unit converters around.

 

I might add more units in the future but so far it has:

 

- 7 units temperature  ( celsius, kelvin, fahrenheit etc. )

- 21 units on length  ( km, miles, nautical miles etc. )

- 15 units on weight   ( kg, lb, etc. )

- 8 units on time ( days, hours, years months etc )

- 18 units on digital memory ( GB, MB TB bytes, kilobytes etc )

- 5 units on speed ( km/h, miles per hour etc.

- 90 units on currencies ( euro, dollar, pounds, dinar etc. )

 

that's 164 units

 

 

  • It has a nice blind rating system. so the more you choose for one answer, the more it will be likely that that one shows up in the suggestions.

 

  • Automatic updates from a currency xml file

 

  • I am working on an automatic update on the whole workflow so i could add new features while you use it. But that is not finished yet.. and i thought.. let's start sharing maybe ill get some nice feedback for possible cool ideas.

 

  • * designed the icons myself, probably could work some more on those too.

 

 

 

it doesn't need explanation...

if you'll just start typing

"5 kilometer to miles..."

or something you will figure out how it works.

 

some screenshots:

 

 

 

 

Edited by designandsuch
Link to comment

@mklement0 : Hi, you can show the categories before a number is typed. In the options for the workflow select 'Argument optional'. I didn't set this by default on purpose, but I'm not sure why anymore... :P thought i had a good reason for that. But i did incorporated it in the scripts.

 

The feet-inch format is a really cleaver suggestion. I would need to rethink how to actually make that work. But.. that opens up new ideas.. like you could also say i want '3 hours and 30 minutes in seconds'..  

 

I will share as soon as i get a solid update!

Link to comment

Very nice.

Suggestion: add support for US-style feet-and-inches specs., commonly used in (human) height measurement; common forms are:

5ft 7in

5'7

5'7"

Also, how about showing the unit categories even before a number is typed? That would enable direct browsing of them.

Well you got me going..!

7.png

 

Here's a quick preview on the update, it's a bit abstract so bear with me.

here i say

1 meter 5*20 yard miles

... as you can see in my debug window it catches it the way i want to.

so now you can give a second value ( the 5*20 yards ) and yes you can do math at the same time too now!

But that second value + unit is optional. if it doesn't catch a number in front of the second unit it will treat it as the output unit.

 

8.png

I did it with random values on purpose.. as i noted earlier, it's more than a 5'7" fix although this is fixed too off course.. since →

 

5'7" cm

 

→ will work. but also "6hours 30min in seconds" etc.

I also made the spaces irrelevant for catching the values. so →

 

5m10mi km

 

will give the same result as →

 

5 mi 10 mi km

.

as you can see this is just the core.. now I've got ot attach all the strings back together. And I'm also cleaning up my code in general. So I will need some time before i can share a solid update. I was just excited to share my little victory, and prove that your suggestions where not  in vain.

If you've got no idea what I'm jabbering about.. well, then you'll have to wait for the actual update :)

Edited by designandsuch
Link to comment

I have a suggestion, could you add the ability to put the currency signs in? I know if you do that and press enter it will revert to the abbreviations like type $, hit enter and it puts in usd, but i would also like to just type it in without having to hit enter and get the results.

Link to comment
  • 2 weeks later...

I agree with you. This workflow is the best Alfred unit converter I've come across yet :D It interprets input sensibly and runs quickly :-)

 

 

i would also like to just type it in without having to hit enter and get the results.

 

Agreed. designandsuch, is there a reason why the workflow requires the user to hit enter to get results? Why not preview the result of all possible matching calculations? I often just want to look up a conversion quickly and hitting enter is an additional key press. Besides, sometimes I might be interested in the other outputs too.

One typo: Line 727 of units_v2.php should use the currency code "nzd" not "znd".

 

EDIT: Seems like the workflow actually does preview the results once you add a space to the end of your query, and that hitting return simply does this for you. Why is the terminating space character required?

Edited by Subject22
Link to comment

I agree with you. This workflow is the best Alfred unit converter I've come across yet :D It interprets input sensibly and runs quickly :-)

 

 

 

Is there a reason why the workflow requires the user to hit enter to get results? Why not preview the result of all possible matching calculations? I often just want to look up a conversion quickly and hitting enter is an additional key press. Besides, sometimes I might be interested in the other outputs too.

One typo: Line 727 of units_v2.php should use the currency code "nzd" not "znd".

 

EDIT: Seems like the workflow actually does preview the results once you add a space to the end of your query, and that hitting return simply does this for you. Why is the terminating space character required?

 

 i don't know. Ask him.

Link to comment

Seems like the workflow actually does preview the results once you add a space to the end of your query, and that hitting return simply does this for you. Why is the terminating space character required?

 

In answer to my own question, as I dislike having to enter a space character to have the workflow display any computed results I found a simple tweak to change this behaviour. Disclaimer: I've never so much as glanced at php before and the script is quite long so for all I know this will break the workflow in some way (though it seems to be working fine so far). Change line 130 in units_v2.php in the following manner.

From:

$this->spaced = (substr($q,-1)==' ');

To:

$this->spaced = true; #(substr($q,-1)==' ');

Also, designandsuch, calculations involving femtometres and picometres give a formula not found error, though based on your comments in the script I'm sure you're aware of this. It's pretty easy to add support for them, so for anyone who's keen just insert this code at around line 412. It's well laid out and easy to understand.

$pm_base = function($pm=0  ){ return $pm  / 1000000000000;};    // m  = pm / 10000000000
$base_pm = function($m=0  ){ return $m  * 1000000000000;};      // pm  = m * 10000000000
$fm_base = function($fm=0  ){ return $fm  / 1000000000000000;}; // m  = fm / 1000000000000000
$base_fm = function($m=0  ){ return $m  * 1000000000000000;};   // fm  = m * 1000000000000000

If you're still developing this then one feature that could be handy would be thousands separators (i.e.: 1,000 rather than 1000).

Edited by Subject22
Link to comment

Thanks a lot for this wonderful tool!

One suggestion: in the digital memory category I would like to choose between the decimal and the binary (1024) system. Possible? Maybe using the alt Key?

Edited by Davide
Link to comment
  • 4 weeks later...

I have a suggestion, could you add the ability to put the currency signs in? I know if you do that and press enter it will revert to the abbreviations like type $, hit enter and it puts in usd, but i would also like to just type it in without having to hit enter and get the results.

 

 

Hi Racer, try the space bar instead of enter.

 

I am using the space for a new feature where you can combine multiple units like 1"2' > cm or 5mi 4inch > m...

 

If I'm not making sense then you'll have to wait for the update. :)

Link to comment

I agree with you. This workflow is the best Alfred unit converter I've come across yet :D It interprets input sensibly and runs quickly :-)

 

 

 

Agreed. designandsuch, is there a reason why the workflow requires the user to hit enter to get results? Why not preview the result of all possible matching calculations? I often just want to look up a conversion quickly and hitting enter is an additional key press. Besides, sometimes I might be interested in the other outputs too.

One typo: Line 727 of units_v2.php should use the currency code "nzd" not "znd".

 

EDIT: Seems like the workflow actually does preview the results once you add a space to the end of your query, and that hitting return simply does this for you. Why is the terminating space character required?

 

Hi subject22, an enter is not required.. a space is hower ( the enter will just ad a space to the end of the line ). the point of this is that the system will validate your input to make sure the correct unit is given.

 

let's say you want to start converting 1 kilo (kilogram) into pounds... you first type 1 then kilo ( the right code for kilogram is "kg" ) which will show up as a suggestion. so in order to know what you are talking about when you select pounds.. the app needs to confirm that you're talking about kilograms(kg). so by pressing enter, alfred will replace your raw 'kilo' into 'kg'... 

 

i could (and did) use alternative codes to recognize what unit you are selecting. but I'm using an even more intelligent suggestion right now in combination with it. which is a bit hard to explain real quick but you could dive into the code to see some hints. 

 

plus I'm working on the double digit feature.. where you can say i want to know the accumulation of "1 kg and 5 pounds in stone" there fore i will leave the 'space' system intact.

Link to comment

Thanks a lot for this wonderful tool!

One suggestion: in the digital memory category I would like to choose between the decimal and the binary (1024) system. Possible? Maybe using the alt Key?

 

Hi Davide,

 

I'm trying to use the International System of Units as much as I can. The decimal and binary units are named differently..for example a binary version of the kilobyte is a kibibyte..  http://en.wikipedia.org/wiki/Kibibyte

 

hope this answers your question

Link to comment

In answer to my own question, as I dislike having to enter a space character to have the workflow display any computed results I found a simple tweak to change this behaviour. Disclaimer: I've never so much as glanced at php before and the script is quite long so for all I know this will break the workflow in some way (though it seems to be working fine so far). Change line 130 in units_v2.php in the following manner.

From:

$this->spaced = (substr($q,-1)==' ');

To:

$this->spaced = true; #(substr($q,-1)==' ');

Also, designandsuch, calculations involving femtometres and picometres give a formula not found error, though based on your comments in the script I'm sure you're aware of this. It's pretty easy to add support for them, so for anyone who's keen just insert this code at around line 412. It's well laid out and easy to understand.

$pm_base = function($pm=0  ){ return $pm  / 1000000000000;};    // m  = pm / 10000000000
$base_pm = function($m=0  ){ return $m  * 1000000000000;};      // pm  = m * 10000000000
$fm_base = function($fm=0  ){ return $fm  / 1000000000000000;}; // m  = fm / 1000000000000000
$base_fm = function($m=0  ){ return $m  * 1000000000000000;};   // fm  = m * 1000000000000000

If you're still developing this then one feature that could be handy would be thousands separators (i.e.: 1,000 rather than 1000).

 

Hi subject 22 again, I answered to quick on your first question.. realizing you've answered it yourself. hacking the is_spaced setting might work for you.. but it will definitely break some features. So i do not advice other people to change this by default.

 

And yes i was aware of my lack of certain formula's.. but I'm glad you where cleaver enough to fix that one yourself. 

I the new version where I will host all the formula's in a seperated file. and I'm thinking of creating a little website for it where people can comment on the formula's and suggest/ fix more formula's.

 

It's too fascinating to keep to myself anway ( the world of units ).. since so many values are so debatable.

 

I'll keep you guys posted!

Link to comment

OK, that's fair enough :-) I'm glad you're still developing this workflow! One thing which puzzled me was that in units_v2.php you include large blocks of data with seemingly repeated entries. Take this one for example:

$this->add_to_lib(1, 0, 'PB', 'digital', '|PB|petabytes|','petabytes', 'Petabytes', 'B|kB|MB|GB|TB');

The "|PB|petabytes|" entry is just the concatenation of two other entries with pipes to delineate them, and the "petabytes" and "Petabytes" entries differ only in capitalisation, something which could be easily adjusted with a simple function. That and the haphazard alignment of the data blocks seems incongruous in an otherwise sophisticated and well laid out script. Why did you choose this format, if you don't mind my asking?

Link to comment
  • 2 weeks later...

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