Python script to open a Google Map location on clipboard?

We generally open the browser to search for a specific site/place on google maps. And if you need to do this task multiple times a day, it becomes very boring. Now you can automate this task where your browser will open automatically and the webpage will show you the google maps of your desired location.


For this purpose, I’m going to use the paperclip package. As this is not the standard package, we need to install it using pip.

>pip install pyperclip
Collecting pyperclip
Building wheels for collected packages: pyperclip
Building wheel for pyperclip ( ... done
Stored in directory: C:\Users\rajesh\AppData\Local\pip\Cache\wheels\92\f0\ac\2ba2972034e98971c3654ece337ac61e546bdeb34ca960dc8c
Successfully built pyperclip
Installing collected packages: pyperclip
Successfully installed pyperclip-1.7.0

Steps to accomplish this:

  • First read the desired address either from the command line argument or from the clipboard.

  • Second using the webbrowser module to automatically open default web browser with the desired address.

  • Require sys module to access the command line stored in argv list.

  • Lastly use pyperclip module to access from the clipboard.

Example Code

#webbrowser module helps in open default web browser of os
from webbrowser import open
#sys contains command line arguments
from sys import argv
#To access clipbord
from pyperclip import paste

if len(argv)>1:
   address = " ".join(argv[1:])
   address = paste()