rikukissa
12/4/2017 - 9:25 PM

Crypto ticker for MacBook Touch Bar

Crypto ticker for MacBook Touch Bar

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

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)