Skip to content

Instantly share code, notes, and snippets.

@rikukissa
Last active December 26, 2017 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikukissa/5c3ecd9312f37942c68439654e997c65 to your computer and use it in GitHub Desktop.
Save rikukissa/5c3ecd9312f37942c68439654e997c65 to your computer and use it in GitHub Desktop.
Crypto ticker for MacBook Touch Bar

Prerequisites

  • Node.js is installed (you can run npm on command line)

Installation

  1. Download BetterTouchTool
  2. Run npm install -g coinmon
  3. Open BetterTouchTool
    • -> Add new widget
    • -> Run Apple Script And Show Return Value
    • -> Advanced Configuration
  4. Paste the script from this gist into the text box
    • Modify the first line of the script to show a price of some other crypto (BTC is default)
set symbol to "BTC"
on trimString(theString)
repeat until theString does not start with " "
set theString to text 2 thru -1 of theString
end repeat
repeat until theString does not end with " "
set theString to text 1 thru -2 of theString
end repeat
return theString
end trimString
on splitString(theString, theDelimiter)
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theArray to every text item of theString
set AppleScript's text item delimiters to oldDelimiters
return theArray
end splitString
on truncatePrice(price)
set pieces to my splitString(price, ".")
set decimals to second item of pieces
set truncated to text 1 thru 3 of decimals
return first item of pieces & "." & truncated
end truncatePrice
set command to "/usr/local/bin/node /usr/local/bin/coinmon --find " & symbol & " --convert EUR | grep " & symbol
set output to do shell script command
set columns to my splitString(output, "│")
set price to third item of columns
set trimmedPrice to my trimString(price)
set truncatedPrice to my truncatePrice(trimmedPrice)
set delta to my trimString(fifth item of columns)
set sign to first item of delta
return delta
if sign is "-" then
set changeSign to "📉"
else
set changeSign to "🚀"
end if
return changeSign & " " & symbol & " " & truncatedPrice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment