Ulauncher/Albert Calculate Anything
Ulauncher/Albert Calculate Anything is an extension for Ulauncher and Albert to calculate things like currency, time, percentage, units, complex equations, base-n expressions and more.
The calculate_anything module does not depend on Ulauncher or Albert so it is extensible for other use cases.
See Features for supported features and Contents for installation instructions and more
Albert Demo
Ulauncher Demo
Features
Calculator for Anything
Currency Converter
: See Currency for examplesTime Converter
: Compute time expressions, convert time to other timezones. See Time for examples.Units Converter
: Compute and Convert units to other units. See Units for examples.Normal Calculator
: Supports functions such ascos
,sin
,tan
. Check Calculator for examples.Complex Numbers
Calculator: Also supports Normal Calculator's functions. Check Calculator for examples.Percentage Calculator
Calculate percentages see Percentages for examples.- Supports all expressions that Normal Calculator and Complex Calculator Support
Base N Calculator
: Calculate numbers and expressions to other number base. See Base N Calculator for examples.- Base 16 (
hex
): Calculates expression to decimal, biniary, octal, color (i.eRGB
,YSV
, etc), Bytes (representation ofstring
) - Base 2 (
bin
), Base 8 (oct
), Base 10 (dec
) - Supports functions:
or
,xor
,and
,mod
,div
,+
,-
,/
- Base 16 (
The calculate anything module does not depend on ulauncher
or albert
. You can adapt it for other projects. See docs for more. The only python files that use dependencies for these launchers are main.py
, __init__.py
in the root of this project.
Dependencies: simpleeval, pint parsedatetime and fixer.io
Currency and Unit converter as well as a Calculator for numbers, complex numbers, percentages and time that supports mathematical functions and Complex Numbers for
Install for Ulauncher
Thus extension depends on requests, pint, simpleeval and parsedatetime. Install them with:
pip install requests pint simpleeval parsedatetime
Open Ulauncher
go to Extensions
> Add extension
and paste https://github.com/tchar/ulauncher-albert-calculate-anything
Install for Albert
Similarly to Ulauncher
the same dependencies are are required.
To install the extension for Albert run
pip install requests pint simpleeval parsedatetime
mkdir -p ~/.local/share/albert/org.albert.extension.python/modules/
git clone https://github.com/tchar/ulauncher-albert-calculate-anything ~/.local/share/albert/org.albert.extension.python/modules/
Open albert, enable Python
extensions and then enable the Calculate Anything
extension.
You can double click it to open module's location and edit __init__.py
to add your preferences.
How to Setup
Albert
If you ar using Albert open the extension location normally at ~/.local/share/albert/org.albert.extension.python/modules/ulauncher-albert-calculate-anything/__init__.py
and edit the preferences mentioned below in the apropriate variable API_KEY
, CACHE
, DEFAULT_CURRENCIES
, DEFAULT_CITIES
, SHOW_EMPTY_PLACEHOLDER
or __triggers__
for the keyword
The extension can work in albert without keywords if you comment out the __triggers__
option, however if another extension has the keyword you type, Calculate Anything won't trigger
(see relevant issue)
Ulauncher
If you are using Ulauncher use the extension preferences.
Set API Key
In order for the currency conversion to work you need to provide a fixer.io API Key. Sign up at https://fixer.io/signup (there is free subscription available) and then go to your fixer.io
dashboard and get your API key.
- ULauncher: Copy your api key to the
API KEY
box in preferences - Albert: Modify the
API_KEY
in__init__.py
Cache
For currency conversion you can enable the cache (located by default at ~/.cache/extension_calculate_anything
) for a minimum of 1 day up to 1 year. This will store the results fetched by fixer.io
to prevent redundant requests. This is especially helpful if you have a free plan on fixer.io
. It will also display the results faster, since no request is made. If all requested currencies have been cached, not request is made to fixer.io
- Ulauncher: Edit
Currency Cache
in the extension preferences - Albert: Edit
CACHE=86400
in__init__.py
and set it to your interval in seconds
Default currency
In the preferences you can define a comma separated list of default currencies to show when typing conversion without target unit/currency.
Defaults to USD,EUR,CAD,GBP,AUD
- ULauncher: Edit in
Default Currencies
preferences - Albert: Edit
DEFAULT_CURRENCIES
in__init__.py
Default cities
In the preferences you can define a comma separated list of default cities when using the time command
- ULauncher: Edit in
Default Currencies
preferences - Albert: Edit
DEFAULT_CITIES
in__init__.py
Show Empty Placeholder
- ULauncher: Default is
No
. Set toYes
to show an empty placeholder when extension doesn't return anything - Albert: Change
SHOW_EMPTY_PLACEHOLDER=True
in__init__.py
Commands and Syntax
To calculate/convert anything you can use the keywords
=
: For currency, units and calculatortime
: For time calculationsdec
/hex
/bin
/oct
: For base-n and calculations
You can go directly to examples or use the ones from the demo
To convert currency type your keyword and then
AMOUNT CURRENCY
to get conversion in the default currencies set in the preferences (requires cache)AMOUNT CURRENCY in(or to) CURRENCY1,CURRENCY2,CURRENCY3
CURRENCY in(or to) CURRENCY1,CURRENCY2,CURRENCY3
To convert units use
AMOUNT UNIT in(or to) UNIT1,UNIT2,UNIT3
UNIT in(or to) UNIT1,UNIT2,UNIT3
Comma separated units and currencies can have spaces between them.
For time you can use the time keyword with a syntax
time
To get the current time plus thedefault cities
you defined in the preferencestime at CITY,[COUNTRY|COUNTRY CODE|STATE CODE]
to get the current time for a specified citytime + AMOUNT [MONTH|YEAR|WEEK|DAY|HOUR|MINUTE|SECOND] [+ AMOUNT ...] [at CITY, [COUNTRY|COUNTRY CODE|STATE CODE]]
to get the time after the calculation at a specified city.
To calculate an expression just type your expression as in the demo
- You can use functions such as
tan
,atan
,asinh
- You can use complex numbers too like
1 + 5i
To calculate percentages you can use one of the following
AMOUNT1% of AMOUNT2
to calculate the AMOUNT1 percent of AMOUNT2AMOUNT1 as % of AMOUNT2
to calculate AMOUNT1 as a percentage of AMOUNT2
If you select one results it will be copied to clipboard.
Examples
Currency
Simple Conversion
- Convert 10 euros to american dollars
10 eur to USD
10 euros to $
10 eurs to dollars
Multiple Conversion
- Convert 10 euros to american dollars, canadian dollars, bitcoin, and mexican pesos
10 EUR to USD,canadian,bitcoin,mexican
Time
You can also add and subtract time
For example if now is 2021-07-05 14:14:42
then you can use the following
NOTE: You can use the keyword now and time interchangeably in Albert
In the following examples the time returned is accompanied by the date time in the default cities
you specified in the extension preferences
time
: Returns 2021-07-05 14:14:42 as well as the date time in the default cities specified in settingstime plus 1 hour
: Returns Today at 15:14:42time + 1 day
: Returns Tomorrow at 14:14:42time minus 1 day
: Returns Yesterday at 14:14:42time + 2 hours
2 minutes 5 seconds: Returns Today at 15:16:47time + 1 year
: Returns 2022-07-05 14:14:42time + 1 year 2 days 2 hours - 4 years 4 minutes
: Returns 2018-07-07 16:10:42
Specifying a custom city
You can use all the commands above followed by at CITY NAME
or at CITY NAME, COUNTRY NAME|COUNTRY CODE|STATE CODE
to get te result in your local time as well as the specified city
time at Prague
time + 2 hours at Madrid
time + 2 hours at Vancouver, CA
: (There are two Vancouvers, so by specifying CA as returns the Canadian Vancouver)time + 2 days 3 seconds at Vancouver, Canada
time + 1 hour + 3 years at Athens, AL
: (Athens AL refenrs to Athens at Alabama)
Units
The units supported are all units that pint supports (which is quite a lot)
Simple Conversion
- Convert 100 fahrenheit to celsius, which is 37.7778 Celcius
100 f to c
Multiple Conversion
- Convert 20 centimeters to inches and meters
20 cm in inches, m
20 cm in inches,meters
Advanced Conversion
- Convert kilometers per meter to centimeters per minute, kilometers per minute, inches per second and centimeters per second.
20 km/h to cm/min, km/minute, in/s, cm/sec
- Convert kilowhats per second to horsepower per hour and megawatts per second
10 kw/sec to hp/h, mw/s
- Convert meters per squared second to kilometers per squared hour
10 m/s^2 to km/h^2
- Convert megabytes per second to gigabytes per hour
10 mb/s to gb/h
You can lieterally convert anything if the apropriate units match
- Convert kilometer * centimeter * second per gibabyte to inches * meter * hour per megabyte
10 km * cm * s / gb to inches * meter * hour / mb
Percentages
Simple Cases
- Calculate what is 10% of 40 (Answer is 4)
10% of 40
- To calculate what percentage of 30 is 5 (Answer is 16.6667%) any of the following works
5 is what % of 30
5 is what % 30
5 as % of 30
5 in % of 30
5 in % 30
Advanced Cases
10% of cos(pi) + 5
: Returns 0.43 + 2 * pi % of cos(pi) + 5
: Returns 0.371328- ``5 as % sqrt(2) + 5`: Returns 77.9519%
1 + sin(pi) as % sqrt(2) + 5
: Returns 15.5904%
Calculator
The calculator works like a normal calculator, but is able to work with complex numbers too.
The following constants exist: pi
, e
, tau
and others from cmath
The following functions exist: phase
, polar
, rect
, exp
, log
, log10
, sqrt
, acos
, asin
, atan
, cos
, sin
, tan
, acosh
, asinh
, atanh
, cosh
, sinh
, tanh
and others from cmath
Simple Cases
10 + sqrt(2)
: Answer is 11.414210 + cos(pi) + 30 * e ^ 2
: Answer is 230.672
Complex Numbers
Use j or i as the imaginary unit
10 + sqrt(2) + j
: Answer is 11.4142 + jcos(1 + j)
: Answer is 0.83373 - 0.988898je ^ (pi * j) + 1
: Answer is 0 (Euler's identity)
Base N Calculator
Use with the keywords hex
, dec
, bin
, oct
by default.
Simple Cases
dec 1000
: Produces result inhex
,bin
,oct
hex ffa12
: Produces result indec
,bin
,oct
as well asbytes
representation of the input query (including spaces)bin 10101
: Produces result indec
,hex
,oct
Special cases with hex
The hex calculator will always produce the byte
representation of its input query.
Color Conversion with hex
If the input is in the format of #xxxxxx where xxxxxx is a valid hex number, it will convert the number representing a color to other color formats.
hex #fa1234
: Produces colors result inrgb
,hsv
,hsl
,cmyk
.
Advanced Cases
dec/hex/bin/oct 10101 and 10110 xor 10 + 1010 - 1010 div 10 and 10101
: Produces the result in all available base-n (dec
,hex
,oct
,bin
)- Digits must be valid in the base you are using (e.g 2012 is invalid for
bin
)
- Digits must be valid in the base you are using (e.g 2012 is invalid for
Extending and More
The calculate_anything module does not depend on ulauncher or albert, only the main.py
(for Ulauncher) and __init__.py
(for albert) do. You can extend it for other cases.
Adding flags
If your currencie's flag is missing you can place it in the extension's flags directory at images/flags/
and restart your launcher or make a pull request to include it.
Make sure to name your flag image in uppercase 2 letter name of your country. To make a currency flag, simply link the country flag you want to the currency e.g ln -s US.svg USD.svg
or add a completely new flat For example American Dollar's flag is in images/flags/USD.svg
. You can use most image formats (i.e svg
, png
)
GitHub
https://github.com/tchar/ulauncher-albert-calculate-anything