//Using IP Sidekick for geolocation in Numbers.app
//hboon@motionobj.com
//https://ipsidekick.com
//Instructions:
//1. Save this file as using-ipsidekick-with-numbers-app.scpt in Script Editor.app
//2. In Numbers app, open your spreadsheet and select the cells with IP address
//..you want to lookup and run this script in Script Editor.app
//This uses the free plan which limits you to 1440 lookups/day.
//For a higher rate limit, look at our paid plans at https://ipsidekick.com
const num = Application('Numbers');
const doc = num.documents[0];
app = Application.currentApplication();
app.includeStandardAdditions = true;
const rangeName = doc.sheets()[0].tables()[0].selectionRange.name();
const range = doc.sheets()[0].tables()[0].ranges[rangeName]
const cells = range.cells
for (let i=0; i<cells.length; ++i) {
const url = "https://ipsidekick.com/" + cells[i].value();
const json = JSON.parse(app.doShellScript("curl " + url));
cells[i].value = json.country.name;
//These fields are available:
//cells[i].value = json.ip;
//cells[i].value = json.country.name;
//cells[i].value = json.country.code;
//cells[i].value = json.currency.code;
//cells[i].value = json.currency.decimals;
//cells[i].value = json.currency.name;
//cells[i].value = json.timeZone.gmtOffset;
//cells[i].value = json.timeZone.name;
//cells[i].value = json.holiday;
}