Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shredthaGNAR/c6e31b5e1450724b9493a8f6262bc529 to your computer and use it in GitHub Desktop.
Save shredthaGNAR/c6e31b5e1450724b9493a8f6262bc529 to your computer and use it in GitHub Desktop.
Cryptocurrencies Touch Bar
set mJson to do shell script "curl -s 'https://api.coinmarketcap.com/v1/ticker/nuls/'"
set AppleScript's text item delimiters to {","}
set keyValueList to (every text item in mJson) as list
set AppleScript's text item delimiters to ""
set theKeyValuePair to item 5 of keyValueList
set AppleScript's text item delimiters to {": "}
set theKeyValueBufferList to (every text item in theKeyValuePair) as list
set AppleScript's text item delimiters to ""
set usdPrice to item 2 of theKeyValueBufferList
set theKeyValuePair to item 13 of keyValueList
set AppleScript's text item delimiters to {": "}
set theKeyValueBufferList to (every text item in theKeyValuePair) as list
set AppleScript's text item delimiters to ""
set change to item 2 of theKeyValueBufferList
set usdPrice to RemoveFromString("\"", usdPrice)
set usdPrice to RoundImperialNumberToTwoDecimals(usdPrice)
set change to RemoveFromString(",", change)
set arrow to ""
if change < 0 then
set arrow to ""
end if
set unformattedValue to "$ " & usdPrice & " " & arrow & ""
return RemoveFromString("\"", unformattedValue)
-- remove character or string from given string
on RemoveFromString(CharOrString, txt)
set AppleScript's text item delimiters to CharOrString
set temp to txt's text items
set AppleScript's text item delimiters to ""
return temp as text
end RemoveFromString
on RoundImperialNumberToTwoDecimals(txt)
set AppleScript's text item delimiters to "."
set decimals to text item 2 of txt
if (count decimals) < 2 then
set decimals to decimals & "0"
end if
set decimals to (text 1 thru 2 of decimals)
set theNumber to text item 1 of txt & "." & decimals
set AppleScript's text item delimiters to ""
return theNumber
end RoundImperialNumberToTwoDecimals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment