Skip to content

Instantly share code, notes, and snippets.

@bachya
Created July 22, 2014 17:19
Show Gist options
  • Save bachya/9168693a094124ccdf63 to your computer and use it in GitHub Desktop.
Save bachya/9168693a094124ccdf63 to your computer and use it in GitHub Desktop.
Fenced Event Challenge

The Scenario

I often need to schedule events and travel time to/from those events (so that others don't book meetings when I'm traveling). Creating those "fenced" events is tedious and doesn't satisfy my need for an elegant solution.

The Desired Outcome

I would like a Launch Center Pro action that:

  1. prompts me to enter an event/date/time combo
  2. prompts me to enter an amount of time (in minutes) for the "beginning fence"
  3. prompts me to enter an amount of time (in minutes) for the "ending fence"
  4. creates three events – one for the event itself and two for the fences – in Fantastical
  • The main event should use the text entered in Launch Center Pro for the title.
  • The fenced events should use "UNAVAILABLE" for the title.
  1. returns to Launch Center Pro

Example

INPUT:

Event: Appointment 8/19 11am Starting Fence: 30 Ending Fence: 45

EXPECTED RESULT:

Three events created:

  1. Appointment, 8/19/2014 from 11:00 AM to 12:00 PM
  2. UNAVAILABLE, 8/19/2014 from 10:30 AM to 11:00 AM
  3. UNAVAILABLE, 8/19/2014 from 11:00 AM to 11:45 AM

A Starting Place

https://launchcenterpro.com/s5vdv1

Right now, this action simply creates a reminder in Fantastical to manually create the fenced events later on.

Rules

  • Any URL scheme-compatible iOS app is fair game.
@n8henrie
Copy link

This doesn't sound too difficult with some help from Pythonista, but I don't own Fantastical so I can't say for sure. The big bummer is that it looks like the Fantastical URL Scheme supports x-callback-url, but doesn't support any way of passing info back.

The ideal (but apparently impossible) workflow would be:

  1. LCP: Free text event datetime as event
  2. LCP: Input before and after fences as appropriate variables
  3. Send all three to Pythonista
  4. Store the fences, send event to fantastical2://parse?sentence=[event]&x-success=[[pythonista://fenced_fantastical?action=run&argv=]]...`
  5. Problem: Fantastical parses the text for you, and returns the proper datetime in a predictable format to Pythonista
  6. Pythonista uses datetime, strftime, time delta, and the stored fenced variables, with the predictable string format from Fantastical, to loop a fantastical URL scheme twice more and make the fences.

The inferior, though workable way:

  1. Have LCP prompt for the event sentence or for each item of the datetime individually, using a consistent date and time formatting.
  2. If you went with a single sentence, use Pythonista and re.search to pick your datetime from the event sentence.
  3. Continue with datetime / timedelta / strftime as per above.

The part that sucks will just be having to manually type in your event datetime in a consistent format (e.g. 02/05/2015 15:30 -- stuff like "next Tuesday" obviously won't fly like they would if you just used Fantastical's date parser).

One other possibility is to see if you can get dateutil installed in Pythonista (looks like others have done it without issue), and use its parser instead -- which is pretty good but not perfect.

I envision an LCP URL like: pythonista://fenced_fantastical?action=run&argv=[prompt:Event name?]&argv=[prompt-num:Event duration in minutes?]&argv=[prompt-num:Beginning fence in minutes?]&argv=[prompt-num:Ending fence in minutes?]

and fenced_fantastical.py to be something simple that accepts the argv, uses datetime / time delta, as described above.

Got to run. Good luck.

@bachya
Copy link
Author

bachya commented Aug 17, 2014

Thank you, @n8henrie! Appreciate your feedback. Excited to share what I came up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment