Jump to content

Google Search for Similar Images


Recommended Posts

Perform a Google Image search based on files on your computer. The images are uploaded to Google, and the list of search results is shown in your browser.
 
Download
 
Get the workflow from GitHub or Packal.
 
Usage
 
Google search supports PNG, JPG, GIF and BMP images only. This workflow
is available as a File Action for any of these filetypes in Alfred.
 
There is also a Hotkey to search based on the current Finder selection. If more
than one image file is selected, only the first will be used.
 
Licence
 
This workflow is released under the MIT License.

Edited by deanishe
Link to comment
  • 1 year later...

What does Alfred's debugger say?

When I select an image and hit the shortcut I get: 

 

ERROR: action.script] ./call_with_finder_selection.applescript:1120:1121: script error: Si attendeva fine linea, ecc. ma è stato trovato “"”. (-2741)

(in english it is saying that it was expecting end of the line but it found “"”)

Link to comment
  • 1 year later...

Really awesome workflow. Thank you for it.

 

One thing I added is that, user can now take an interactive screenshot and search that on Google. 

 

Here is the modified workflow if you wish to perhaps add it to your own one. :)

 

Edited by nikivi
Link to comment
  • 1 month later...

Here's what the debugger puts out when I run the workflow:

 

[2017-09-28 08:42:44][ERROR: action.script] Traceback (most recent call last):
  File "url_for_image.py", line 85, in <module>
    sys.exit(main())
  File "url_for_image.py", line 80, in main
    raise ValueError("Couldn't understand server response")
ValueError: Couldn't understand server response

 

 

When I double-tap 'command' with an image selected in finder, and select 'Search For Similar Images' in the file action list, instead of searching Google the workflow opens '/Users/MY_NAME/Dropbox/Alfred.alfredpreferences/workflows/user.workflow.4DEF597C-7E7E-4A83-B859-E1627D4C7939' in finder.

 

Is there any other useful information I could provide? Thanks for looking at this.

Link to comment
1 hour ago, sr_navarre said:

Here's what the debugger puts out when I run the workflow:

 

[2017-09-28 08:42:44][ERROR: action.script] Traceback (most recent call last):
  File "url_for_image.py", line 85, in <module>
    sys.exit(main())
  File "url_for_image.py", line 80, in main
    raise ValueError("Couldn't understand server response")
ValueError: Couldn't understand server response

 

Impossible to say without knowing what image you're uploading.

 

At any rate, I've just released v2.0, which will work better with Alfred 3.

 

1 hour ago, sr_navarre said:

When I double-tap 'command' with an image selected in finder, and select 'Search For Similar Images' in the file action list, instead of searching Google the workflow opens '/Users/MY_NAME/Dropbox/Alfred.alfredpreferences/workflows/user.workflow.4DEF597C-7E7E-4A83-B859-E1627D4C7939' in finder.

 

Is that definitely my workflow? There's nothing in my code that would cause that behaviour.

 

2 hours ago, sr_navarre said:

Is there any other useful information I could provide?

 

The image you're trying to search for.

 

Link to comment

I've just tried again with v2.0, and I'm still getting the same response (opening the finder to the folder I mentioned above). This time I tried to search for the image I attached to this reply, and I got the following message in the debugger:

 

[2017-09-28 11:23:24][ERROR: action.script] Traceback (most recent call last):
  File "url_for_image.py", line 85, in <module>
    sys.exit(main())
  File "url_for_image.py", line 80, in main
    raise ValueError("Couldn't understand server response")
ValueError: Couldn't understand server response

 

 

caramelo.thumb.jpg.5623aecbf9d9e9301cd1d5bde63676bb.jpg

Link to comment

Thanks for all your work on this. Here's the debug info for v2.0.1; I attached the image I searched for this time.

 

Starting debug for 'Google Similar Images'

[2017-09-28 13:13:52][ERROR: action.script] uploading u'/Users/MYNAME/Pictures/Backgrounds/kgm58S7.jpg' to Google ...
cmd=['/usr/bin/curl', '--include', '--silent', '--user-agent', 'alfred-similiar-image-search 0.1 ()', '--form', 'image_url=', '--form', 'filename=', '--form', 'h1=en', '--form', 'bih=179', '--form', 'biw=1600', '--form', 'encoded_image=@/Users/MYNAME/Pictures/Backgrounds/kgm58S7.jpg', 'https://www.google.com/searchbyimage/upload']
[response] HTTP/2 302 
[response] location: https://www.google.com/search?tbs=sbi:AMhZZiuf4HqV0Q8qcUIY7HIlG5icYpS2sk04vgdcuPnoutrZz0Ya2xHH-mU1Krau_1irKW5Z6wEiXLB9r_1hgxdBdWbMLN4cKDwEUIG4-Ic32omifoEcE8Kiznh46SszXdq-RhB0RNVYjWAFnEAnALR1hqpGD3koYlz8y9oIetKGIBNHQyL814ekwJTLvUEM748_1DGDcVC2qIu6V2NIvwcleg4OWLPfmQilnWHu6l3ul1hjqISh3r8M5wXpgqOO-QqsR23aTxJTSOqTREz5ySs4WUrL3rXexQ8Rdss7JrMIF-vpfSJjUkXEVK5BGo0Tqij3xhz9BQmgQCCCqD9EgWiqF4eeYwr9zS4Tg&h1=en&bih=179&biw=1600
[response] cache-control: public, max-age=21600
[response] date: Thu, 28 Sep 2017 17:13:58 GMT
[response] expires: Thu, 28 Sep 2017 23:13:58 GMT
[response] content-type: text/html; charset=UTF-8
[response] x-content-type-options: nosniff
[response] server: quimby_frontend
[response] content-length: 627
[response] x-xss-protection: 1; mode=block
[response] x-frame-options: SAMEORIGIN
[response] alt-svc: quic=":443"; ma=2592000; v="39,38,37,35"
[response] 
[response] <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
[response] <TITLE>302 Moved</TITLE></HEAD><BODY>
[response] <H1>302 Moved</H1>
[response] The document has moved
[response] <A HREF="https://www.google.com/search?tbs=sbi:AMhZZiuf4HqV0Q8qcUIY7HIlG5icYpS2sk04vgdcuPnoutrZz0Ya2xHH-mU1Krau_1irKW5Z6wEiXLB9r_1hgxdBdWbMLN4cKDwEUIG4-Ic32omifoEcE8Kiznh46SszXdq-RhB0RNVYjWAFnEAnALR1hqpGD3koYlz8y9oIetKGIBNHQyL814ekwJTLvUEM748_1DGDcVC2qIu6V2NIvwcleg4OWLPfmQilnWHu6l3ul1hjqISh3r8M5wXpgqOO-QqsR23aTxJTSOqTREz5ySs4WUrL3rXexQ8Rdss7JrMIF-vpfSJjUkXEVK5BGo0Tqij3xhz9BQmgQCCCqD9EgWiqF4eeYwr9zS4Tg&amp;h1=en&amp;bih=179&amp;biw=1600">here</A>.
[response] </BODY></HTML>
[response] 
Traceback (most recent call last):
  File "url_for_image.py", line 95, in <module>
    sys.exit(main())
  File "url_for_image.py", line 90, in main
    raise ValueError("Couldn't understand server response")
ValueError: Couldn't understand server response

 

kgm58S7.thumb.jpg.56f33ff2783a0fdaf4415182434ddc5c.jpg

 

Hope that helps.

Link to comment
  • 2 years later...

This doesn't work in Alfred 4 anymore. I get notification ("Searching for similar images" and that's it. It is super useful, can we get an update?

 

EDIT: spoke to soon. It just took a handful of minutes to open the results page for whatever reason.

Edited by Stooovie
Link to comment
  • 1 year later...

@deanishe This workflow doesn't seem to working. Do we need to make changes before running this?

 

error:

[23:30:38.514] ERROR: Google Similar Images[Run Script] uploading u'/Users/<USER>/Downloads/CoolBeans/Images/americano@2x.jpg' to Google ...
cmd=['/usr/bin/curl', '--include', '--silent', '--user-agent', 'alfred-similiar-image-search 0.1 ()', '--form', 'image_url=', '--form', 'filename=', '--form', 'h1=en', '--form', 'bih=179', '--form', 'biw=1600', '--form', 'encoded_image=@/Users/<USER>/Downloads/CoolBeans/Images/americano@2x.jpg', 'https://www.google.com/searchbyimage/upload']
Traceback (most recent call last):
  File "url_for_image.py", line 95, in <module>
    sys.exit(main())
  File "url_for_image.py", line 88, in main
    url = similar_images_url(filepath)
  File "url_for_image.py", line 68, in similar_images_url
    output = subprocess.check_output(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 223, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/usr/bin/curl', '--include', '--silent', '--user-agent', 'alfred-similiar-image-search 0.1 ()', '--form', 'image_url=', '--form', 'filename=', '--form', 'h1=en', '--form', 'bih=179', '--form', 'biw=1600', '--form', 'encoded_image=@/Users/<USER>/Downloads/CoolBeans/Images/americano@2x.jpg', 'https://www.google.com/searchbyimage/upload']' returned non-zero exit status 7
[23:30:38.516] Google Similar Images[Run Script] Processing complete
[23:30:38.524] Google Similar Images[Run Script] Passing output '' to Run Script

 

Link to comment
  • 2 months later...

May I reopen this old thread?

 

I am trying to use this workflow in Alfred 4 on a M1 iMac and OS 12.3.1.

 

I get this error:

 

[13:35:10.765] Logging Started...
[13:35:57.793] Logging Stopped.
[13:36:02.187] Logging Started...
[13:36:08.065] Google Similar Images[Hotkey] Processing complete
[13:36:08.072] Google Similar Images[Hotkey] Passing output '' to Run Script
[13:36:08.235] ERROR: Google Similar Images[Run Script] ./call_with_finder_selection.applescript:1118:1119: script error: Expected end of line, etc. but found “"”. (-2741)
[13:36:08.239] Google Similar Images[Run Script] Processing complete
[13:36:08.240] Google Similar Images[Run Script] Passing output '' to Post Notification

 

I have Python3 (installed via homebrew) in, and wasn't sure if I needed to update lines in the workflow like /usr/bin/python url_for_image.py "$1" to refer to where my python is? Which is in /Library/Frameworks/Python.framework/Versions/3.10/bin/python3

Link to comment

Thanks. I am in another thread on the Keyboard Maestro forums and the person says the workflow works for him. Not sure why it's not working for me. Can you tell me how you installed Python? Using Homebrew it installs "python3" and the Python commands in the workflow don't work, which feels like it might be part of the issue. Can you tell me what the "best" way to install Python is, and maybe tell me where it should be installed? I only have python3 in /Library/Frameworks/Python.framework/Versions/3.10/bin/python3, currently

Link to comment
  • 6 months later...

Hi all,

 

may someone help me understand what i'm doing wrong?

  • M1 MacbookPro 
  • 13.0.1
  • Workflow version 2.1.1
  • Installed Python 3

 

(Thanks to deanishe for all the workflow and the support given through the years)

 

Error log
 

[16:29:43.274] ERROR: Google Similar Images[Run Script] Traceback (most recent call last):
  File "/Users/nicolaefflandrin/Dropbox/Cloud Services/Sync/Alfred/Alfred.alfredpreferences/workflows/user.workflow.9F15584E-5AB0-4447-B21E-DE92D82FC37C/url_for_image.py", line 95, in <module>
    sys.exit(main())
  File "/Users/nicolaefflandrin/Dropbox/Cloud Services/Sync/Alfred/Alfred.alfredpreferences/workflows/user.workflow.9F15584E-5AB0-4447-B21E-DE92D82FC37C/url_for_image.py", line 85, in main
    filepath = args[0].decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'?


Thanks to who will have time and patience to help me. 🙂

Edited by nicola.efflandrin
Thanking Deanishe
Link to comment
  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...