Skip to content

Instantly share code, notes, and snippets.

@dvcrn

dvcrn/mona.applescript

Last active Nov 20, 2017
Embed
What would you like to do?
Fetch crypto price in applescript
# example to fetch the current MONA price in JPY
# needs http://www.mousedown.net/mouseware/JSONHelper.html
# replace 'neo' with any other ID supported by coinmarketcap
# using coinmarketcaps convert API to add `price_jpy` to the result
set json_data to (do shell script "curl https://api.coinmarketcap.com/v1/ticker/monacoin/?convert=JPY")
tell application "JSON Helper"
set json_data to read JSON from json_data
end tell
set first_result to beginning of json_data
set price to price_jpy of first_result as number
# round result to 2 decimal places
set rounded_price to (round (price * 100)) / 100
set result_string to "" & rounded_price & ""
# (...)
# do what you want with result_string
# example to fetch the current NEO price
# needs http://www.mousedown.net/mouseware/JSONHelper.html
# replace 'neo' with any other ID supported by coinmarketcap
set json_data to (do shell script "curl https://api.coinmarketcap.com/v1/ticker/neo/")
tell application "JSON Helper"
set json_data to read JSON from json_data
end tell
set first_result to beginning of json_data
set price to price_usd of first_result as number
set result_string to "$" & price
# (...)
# do what you want with result_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment