Pythonista 3 script to save current location to OmniFocus

Because why not.

You can save this as an icon to the home screen with a nice car icon or some such.

The note contains your address and links to the location that will open several popular map apps.

import location
import webbrowser
import time
import urllib.request, urllib.parse, urllib.error
from string import Template

def locationToNote( address, lat, lng):

  tpl = Template (
          "$name" +
          "$street" +
          "$city" +
          "$zip" +
          "$country" +
          "\n" +
          "Apple:$lat,$long\n" +
          "\n" +
          "Google:$lat,$long/@$lat,$long,12z\n" +
          "\n" +
          "Open Street Map:$lat&mlon=$long#map=12/$lat/$long/m\n" +
          "\n" +
          "TomTom: tomtomhome://geo:action=show&lat=$lat&long=$long&name=Pin\n" +
          "\n" +
          "Waze: waze://?ll=$lat,$long&navigate=yes");

  name = sanitiseAddressField(address.get("Name"));
  street = sanitiseAddressField(address.get("Street"));

  if (name == street):
    street = "";

  params = {
          "name"    : name,
          "street"  : street,
          "city" :    sanitiseAddressField(address.get("City")),
          "zip" :     sanitiseAddressField(address.get("ZIP")),
          "country" : sanitiseAddressField(address.get("Country")),
          "lat" :     lat,
          "long" :    lng};

  return tpl.substitute(params);

def sanitiseAddressField(val):
  return (val + "\n") if val != None else "";

print("Getting Location...")
here = location.get_location();

lat = here.get("latitude");
lng = here.get("longitude");
address = location.reverse_geocode(here)[0];
timestr = time.strftime(" (%H:%M)");
note = locationToNote(address, lat, lng);
name = address.get("Name");
print("Street: " + name + timestr);
ofnote = {"name" : "Pin: " + name + timestr, "note" : note};"omnifocus:///add?" + urllib.parse.urlencode(ofnote).replace('+','%20'));
1 Like

Nice idea.

Can’t test it now, but… shouldn’t this line be like below? ;)
note = locationToNote(address, lat, long);

Argh. Yes! I converted these from Pyhonista2->3 using the built in conversion script and it changed all the variables named “long” to “int”, thought I’d found them all (I have several similar scripts).

[Updated the script]


1 Like

Will try it later. Very nice idea. I guess I won’t need Take Me There anymore :)))

Yeah, I never found a “where did I park” app that I liked, and as an OF user, this is handy, especially when you add it to the home screen:

1 Like