Skip to content

Instantly share code, notes, and snippets.

@hboon
Last active October 15, 2017 14:49
Show Gist options
  • Save hboon/26ed9723dae90bfeb718ada9bb6809e8 to your computer and use it in GitHub Desktop.
Save hboon/26ed9723dae90bfeb718ada9bb6809e8 to your computer and use it in GitHub Desktop.
Using IP Sidekick for geolocation in Numbers.app
//Using IP Sidekick for geolocation in Numbers.app
//[email protected]
//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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment