Google Reverse Image Search?


#1

Has anyone built a macro that automatically uploads an image to Google for a reverse image search?

The user interface of Google image search requires the user to drag & drop an image into the search bar, or click a button and then select a file from the local disks. Both things seem cumbersome to emulate with KBM.

What Google also allows is to search by image URL, which would look like this:

https://www.google.com/searchbyimage?image_url=https://www.dropbox.com/s/i2ti20cll3n04a1/KBM-Screenshot-tmp.png?dl=1

This, however, requires that the image to be searched first be uploaded to some webserver. In the above example, I used my Dropbox account. This slows things down, and introduces another potential point of failure.

The macro I’d like to build would…

  • let me select a portion of my screen to “screenshoot”
  • save that as a temporary local file
  • emulate whatever my browser would do behind the scenes after I drag & drop this file onto Google’s image search bar (but without having to resort to actual mouse actions)

Could this, perhaps, be done with JavaScript?


#2

I use this Alfred workflow to do this:

The code is open source if you do want to transfer it to KM macro. :slightly_smiling_face:


#3

Thanks for the hint.

Apparently the “secret sauce” of this workflow is this python script. It reads a local file and then uploads it to Google Image Search.

I’m not familiar with Python. But I imagine one could run this script using KBM’s “Shell Script” action, provided that Python is installed on the system.


#4

Hey Leonard,

There’s a Safari extension that will let you do this with images in web pages.

I was able to get the Python script working by:

  1. Saving the source with the same “Reverse_Image_Search.py”.
  • Making it executable.
  • Moving it to my folder for 3rd party Unix executables.
  • Running it in a shell script action with the path to the desired image as the argument.

Google ⇢ Reverse Image Search.kmmacros (6.4 KB)
Reverse_Image_Search.py.zip (2.1 KB)

-Chris


#5

Hey Folks,

I added the executable Python file (Reverse_Image_Search.py) to my post above.

You can open the script in BBEdit or TextEdit to see what’s in it, of course if you’re unfamiliar with Python it may look like so much Greek.  :wink:

I did try to make a single integrated macro, but I couldn’t figure out how to feed the Python script the file-path argument it needs when calling it from a text variable…

-Chris


#6

Thanks Chris,

I use the Alfred workflow almost every day. I’m happy to finally be able to use this feature with Keyboard Maestro.


Cary