Wednesday, January 16, 2013

Making an app with an applescript on your mac that gets you public transit directions


At the end of the day in my office, just before leaving the office I generally check google maps for getting public transit directions and time tables. Google Maps lets you save driving directions with a link "Save to My Maps" under the directions to your "My places". But this is not the case with public transit directions. Which in my opinion sucks. This might sound trivial to some one who uses their car to goto office. Trust me it's a heck of nuisance to someone like me as I use public transit all the time.

Generally, what I do is I open a new tab in my browser and then open the page "maps.google.com" and then click on public transit, then type the addresses, let's say for example home or office if you've saved them or type the entire addresses and then select the train or bus from options based on your public transit mode. Again, it doesn't sound that big of a deal if you have to do this once in a month. But I do this million times in a month. So, I've started looking for some sort of a way to save it to my places.

Whatever I found googling didn't help me at all. In the end I've decided to make an app for my self with an applescript on my mac. Then I thought of putting it here if someone is interested in knowing how I did it. Here we go:

First goto maps.google.com and get the public transit directions for your destination. Let's say we need public transit directions from Hoboken HBLR Terminal to Penn Station, New York, NY. I know that there is a PATH train service that runs from Hoboken to 34th street which is where Penn station. Of course, you don't need to know anything of this at all. As I know I always select the option "train" from show options. Then I get the link to directions from share symbol next to My places. This is what I've got here:

https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0



Once you have this link, go and open applescript editor (Press command + space bar and type applescript) and add this code below and then save it to where ever you want to have it in your system. I put it on my desktop.

Applescript Code:

do shell script "open -a Safari \"https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0\""


The above code opens the tab with public transit directions in Safari.

To open the page in a default browser, just remove -a Safari:

do shell script "open \"https://maps.google.com/maps?saddr=Hoboken+HBLR+Terminal&daddr=Penn+Station,+New+York,+NY&hl=en&ll=40.740982,-74.011202&spn=0.027411,0.05579&sll=40.740982,-74.012575&sspn=0.027411,0.05579&geocode=Fc-MbQId92SW-yk7lmyP4lnCiTHoGLLYwLjysQ%3BFfTNbQIdlPKW-yELxignjABkPin5tzQUrlnCiTELxignjABkPg&oq=Penn&dirflg=rT&ttype=now&noexp=0&noal=0&sort=def&mra=ls&t=m&z=15&start=0\""


Before making it an app you can simply try running it with "Run" on the editor which shows you whether it is working or not. Once you know that it is working the way you wanted it to be go for save options and there select "Application" in the "File Format" drop down menu. Once you save it as application, let's say on your Desktop you can simply drag it onto your Dock.

Once you have it there on the dock you can simply click it just like you open any other application. This opens public transit directions with your selected public transportation mode with the latest time table.

By the way, if you'd like to save your script so that you can modify or refer to in the future then I say save another copy some where in SCPT format by choosing SCPT from File Format drop down menu options.

2 comments:

My Knotty Mind - Labyrinth said...

Of course, one can add the page to their bookmarks and make it show up in their bookmars bar under the address bar as well. The only downside to it is that browser has to be already open.

ibraheimnabor said...

Casino - Jammy! Casino Hotel & Spa
Welcome to Jammy! Casino Hotel & Spa! Enjoy 24/7 성남 출장샵 live entertainment, amazing 강릉 출장안마 dining and exciting casino 울산광역 출장안마 gaming. Come 창원 출장안마 join the amazing 화성 출장샵 Jammy! Casino Hotel & Spa

PBS Script Generator: Interdependent dropdown/select menus in Javascript

PBS SCRIPT GENERATOR
SH/BASH TCSH/CSH
Begin End Abort

About Me

LA, CA, United States
Here I write about the battles that have been going on in my mind. It's pretty much a scribble.

Sreedhar Manchu

Sreedhar Manchu
Higher Education: Not a simple life anymore