- Install BetterTouchTools and "JSON Helper for Apple Script" from the App Store.
- Set up a widget inside BetterTouchTools
- Global -> Click
+Widget
- In
Select toucbar wigdet
pick the optionRun Apple Script and Show Return Value
- Click
Advanced Configuration
- Paste the script and click
Run Script
to validate that it works.
-- Settings
set coinName to "bitcoin" -- Name of coin
set currencry to "usd" -- Currency (usd or eur)"
set showChange to false -- Should show percentage change
set roundingDeliminator to 2 -- Number of numbers after the deliminator
-- End of settings
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on roundThis(n, numDecimals)
set x to 10 ^ numDecimals
(((n * x) + 0.5) div 1) / x
end roundThis
tell application "JSON Helper"
set fetch_api to fetch JSON from "https://api.coinmarketcap.com/v1/ticker/" & coinName & "/?convert=EUR" with cleaning feed
end tell
set change to percent_change_24h of first item of fetch_api
if currencry = "usd" then
set raw_usd_price to price_usd of first item of fetch_api
set fix_deliminator to replace_chars(raw_usd_price, ".", ",") as number
set rounded to roundThis(fix_deliminator, roundingDeliminator)
set price to "$" & (rounded as inches as string)
end if
if currencry = "eur" then
set raw_eur_price to price_eur of first item of fetch_api
set fix_deliminator to replace_chars(raw_eur_price, ".", ",") as number
set rounded to roundThis(fix_deliminator, roundingDeliminator)
set price to "€" & (rounded as inches as string)
end if
if showChange then
return price & " [" & change & "%]"
end if
return price
- Tweak the settings
- Set a name
- Set
Execute this script every x seconds
to 60 seconds or something to avoid spaming the network - Pick the TouchBar button color
- Set a icon by dragging a image over the Icon slot. Here are some nice icons.
- Rince and repeat for as many coins you want.
At the top of the script there are some values you can change to set another coin, set the currency and how many numbers after the deliminator (in case the coin is worth less than a dollar).
How to find coin name
You can find the coinName
from the url from coinmarketcap https://coinmarketcap.com/currencies/{coinName}/
Great script, I do do often get many more numbers than 2 after the deliminator with my EOS currency (but not all the time) :) Cant spot the error though