3

How can I get AppleScript to run this query and save each value (country, city, etc.) as an AppleScript variable?

http://ip-api.com/json/8.8.8.8?fields=country,city,isp,org,as,mobile,proxy,message

I'm trying to get information about IP and domain and set the value of some variables.

I was not sure how to even run the query from AppleScript so I used do shell script to call curl:

set IPAddress to "8.8.8.8"
set link to "http://ip-api.com/json/" & IPAddress & "?fields=country,city,isp,org,as,mobile,proxy,message"
set curl_command to "curl " & link

do shell script curl_command

The result is JSON formatted text. Is AppleScript's text delimiter the only option for parsing the result?

  • As a tip, use <!-- language: lang-none --> to turn off syntax highlighting where it's not wanted, such as that URL above. – TRiG Dec 18 '17 at 17:51
  • If the below answered your question please accept the answer. – ʀ2ᴅ2 Nov 15 '18 at 17:27
8

The easiest way is to use JSON Helper app available on the AppStore. Then you simply do something like this:

tell application "JSON Helper"
    set json to fetch JSON from "http://ip-api.com/json/8.8.8.8?fields=country,city,isp,org,as,mobile,proxy,message"
    set countryName to |country| of json
end tell

Result: "United States"

  • Nice utility for free! In the past I've used jq in bash script, but will use this the next time I need to parse JSON. from AppleScript. +1 – user3439894 Dec 18 '17 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .