thewondermint Posted April 2, 2013 Posted April 2, 2013 So I'm trying to come up with a way to track my daily mileage. Assuming I have addresses stored in Contacts.app, here's how I envision it working: - Using the home addresses as the reference, I want to select two contact cards and send them into Google Maps and have it return the mileage back into Alfred. The typical Google Maps search looks like this: https://maps.google.com/maps?q={query} My goal is to have something that looks more like this: https://maps.google.com/maps?saddr={query1}&daddr={query2} where {query1} is the starting address and {query2} is the destination address. So far I've tried: - Creating a contacts action that sends the address to Google Maps. This gets me 1/3rd of the way. - Copying the first address to my clipboard and then performing option one (Contacts action) on the second address and then pasting the first address into maps when it pops up. This doesn't save me nearly enough time. First: is this even remotely possible? Second: I'd love to know how to do something like this, I'm not really interested in having someone do this for me. I'm an absolute beginner when it comes to scripting of any kind, but I'd love to learn. What am I missing or not considering? Thanks! -Andrew
dfay Posted April 2, 2013 Posted April 2, 2013 If you're the only one using this, and you always leave from the same place, you could just hard code the first address
thewondermint Posted April 2, 2013 Author Posted April 2, 2013 If you're the only one using this, and you always leave from the same place, you could just hard code the first address Great idea! I hadn't thought of that. So it would look something like this? https://maps.google.com/maps?saddr={my address}&daddr={query} where query is the destination? That will definitely work, but what if I want to start from somewhere other than my home address?
dfay Posted April 2, 2013 Posted April 2, 2013 I'd look at the first example here: http://www.alfredforum.com/topic/1283-how-to-script-filters-reusing-a-single-script-filter-or-chaining-multiple-together/ It inputs last name, writes it to a temporary file, calls a second search action that inputs first name, reads last name from the temporary file, deletes the temporary file, and finally outputs first name last name. You'd just need to modify it to get the addresses from contacts instead of user input (which it sounds like you've figured out already), and change the echo command in the 2nd bash script to include all the necessary bits for the google maps URL, then replace the Post Notification with a Open URL.
thewondermint Posted April 2, 2013 Author Posted April 2, 2013 I'd look at the first example here: http://www.alfredforum.com/topic/1283-how-to-script-filters-reusing-a-single-script-filter-or-chaining-multiple-together/ It inputs last name, writes it to a temporary file, calls a second search action that inputs first name, reads last name from the temporary file, deletes the temporary file, and finally outputs first name last name. You'd just need to modify it to get the addresses from contacts instead of user input (which it sounds like you've figured out already), and change the echo command in the 2nd bash script to include all the necessary bits for the google maps URL, then replace the Post Notification with a Open URL. You're giving me way too much credit :-P I completely understand the concepts and logic behind using the second bash script (I barely even know what a bash script is) to achieve what I want, but I have absolutely no idea how to modify it to force me to choose addresses instead of user input. Where do I look for next steps or what should I be changing?
dfay Posted April 2, 2013 Posted April 2, 2013 Unless there's another way to get contact info. in Alfred, I don't see an easy way to select start and destination address until this issue is addressed: http://www.alfredforum.com/topic/331-descriptive-name-for-custom-call-actions-in-main-alfred-window/
dfay Posted April 2, 2013 Posted April 2, 2013 (edited) Here is how to do the hardcoded version (i.e. select destination only). 3 elements 1) Contact Action linked to 2) a one line bash script (escaping everything except spaces) - this removes line breaks from the address: echo "{query}" | tr "\n" " " linked to 3) a one line bash script (escaping everything except spaces): open "http://maps.google.com/maps?saddr=yourstartingaddress&daddr={query}" Edited April 2, 2013 by dfay
dfay Posted April 2, 2013 Posted April 2, 2013 If you don't want to enter it yourself, it's here: Mapper.alfredworkflow
thewondermint Posted April 2, 2013 Author Posted April 2, 2013 If you don't want to enter it yourself, it's here: Mapper.alfredworkflow Awesome! I had it set up with a URL scheme that looks like this: https://maps.google.com/maps?saddr=(my address)+&daddr={query} It seems like it performs in general the same way? Thanks so much for the bump in the other post and for all your help in general!
zapacoman Posted April 13, 2013 Posted April 13, 2013 Instead of hard coding the starting location, couldn't you pull the current location leveraging something like this: http://stackoverflow.com/questions/4066699/how-to-get-users-position-in-google-maps-api that would be amazing.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now