Is "click on found image" the only option for searching google images?

I have created a macro that allows Google Image Search by Screen Region Capture or from selected image files from Finder.
You may want to try it and see if that works for you. It does not require other application (eg Python, Alfred) so to make usage easier for users.

https://forum.keyboardmaestro.com/t/google-image-search-by-screen-region-or-finder-macro-km10/27612/2

2 Likes

Works great!! I'm happy with Alfred, but I reckon this is perfect for @ppayne.

1 Like

noisneil,
you might want to download the v1.1 as I made some changes, like open URL in Default Application.

1 Like

For no reason other than fun, I rebuilt your macro. To be clear, this is in no way improved; I just wanted to rebuild it as an exercise. :slight_smile: I had no idea you could perform an image search in a shell script. So tidy!

Reverse Image Search.kmmacros (50 KB)

Macro screenshot

1 Like

Thanks, I've purchased Alred's power pack since it looks like it has some powerful tools I can use. I imported your script, assigned a keyboard shortcut in the Hotkey box, but get this "the application can't be opened" error. Any idea what I'm doing wrong?

Screen Shot 2022-05-10 at 17.57.47

Thanks for the help. I've been using KM for years but I can't follow what your script is doing. Can you give me some details?

Hmm. So the workflow is successfully installed but then throws up an error when you try and run it on an image file? Perhaps it's a permissions issue?

This is the source.

@macdevign_mac cleverly thought to upload to Google Image Search via a shell script. The macro will either upload the currently selected file or take a screenshot and then upload that.

I have it installed and manually assigned a keyboard shortcut. When I run it I get the error from Alfred. Below is some debugging code if that helps. Maybe there's an additional piece I don't have installed?

[22:49:04.774] Google Similar Images[Hotkey] Processing complete
[22:49:04.778] Google Similar Images[Hotkey] Passing output '' to Run Script
[22:49:04.984] Google Similar Images[External] Processing complete
[22:49:04.987] Google Similar Images[External] Passing output '/Users/pp/Documents/BTSync/Peter Sync/ARCHIVE/POST/doukichan and senpaisan ganbare doukichan and 1 more drawn by yomu_sgt_epper  DanbooruCLVX_1.jpg' to Run Script
[22:49:04.989] Google Similar Images[External] Passing output '/Users/pp/Documents/BTSync/Peter Sync/ARCHIVE/POST/doukichan and senpaisan ganbare doukichan and 1 more drawn by yomu_sgt_epper  DanbooruCLVX_1.jpg' to Post Notification
[22:49:04.995] ERROR: Google Similar Images[Run Script] /Users/pp/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/99F96803-F81B-4F14-A367-F163129D9D0A: line 3: /usr/bin/python: No such file or directory
[22:49:04.997] Google Similar Images[Run Script] Processing complete
[22:49:04.998] Google Similar Images[Run Script] Passing output '' to Open URL
[22:49:05.050] STDERR: Google Similar Images[Run Script] 1 image(s) selected
[22:49:05.054] Google Similar Images[Run Script] Processing complete
[22:49:05.055] Google Similar Images[Run Script] Passing output '' to Post Notification

Did you try downloading from here?

Possible clue?

LOL, thanks. I've never properly learned Python.

So I've installed python with Brew and now I have python3 in /opt/homebrew/python3. I am randomly guessing I need to edit the script to point to that? I changed it to

/opt/homebrew/python3 url_for_image.py "{query}"

and now the error I get is

[14:23:47.041] Google Similar Images[Hotkey] Processing complete
[14:23:47.048] Google Similar Images[Hotkey] Passing output '' to Run Script
[14:23:47.175] ERROR: Google Similar Images[Run Script] ./call_with_finder_selection.applescript:1120:1121: script error: Expected end of line, etc. but found “"”. (-2741)
[14:23:47.177] Google Similar Images[Run Script] Processing complete
[14:23:47.180] Google Similar Images[Run Script] Passing output '' to Post Notification

Am I getting warmer?

:roll_eyes:

The reason I ask is that the workflow I attached to my first post was exported from my Alfred library. I think perhaps you need to download the workflow from the site and run it to install the python script. As I said, I didn't have to think about python; I just installed it and it worked, which is what has led me to this line of thinking.

I am trying it on two different machines. On the newest machine, I did re-download it from the original source.

So am I doing the right thing by editing the code to point to opt/homebrew/python3 for the park that calls the above line?

OK I've deleted my old workflow and re-downloaded it again from the above link. The keyboard shortcut is removed and the Python command in the upper middle box is restored to /usr/bin/python

So I've now added just the keyboard shortcut and run it. After turning on Accessibility permissions(which it didn't ask for before) I get this debugging feedback

[15:03:41.874] Google Similar Images[Hotkey] Processing complete
[15:03:41.878] Google Similar Images[Hotkey] Passing output '' to Run Script
[15:03:42.017] ERROR: Google Similar Images[Run Script] ./call_with_finder_selection.applescript:1120:1121: script error: Expected end of line, etc. but found “"”. (-2741)
[15:03:42.018] Google Similar Images[Run Script] Processing complete
[15:03:42.022] Google Similar Images[Run Script] Passing output '' to Post Notification

Do I have the right python installed? I just did it through Brew.

Sorry mate, I have no idea why it's not working. All I did was download the workflow and double click it.

I'll try to find out what's going on. Can you tell me what terminal reports when you type "which python"? In my case it insists python is not installed, but python3 is. Which means I likely have something set up wrong.

Is it possible for you to send me the output of "which python" (or "which python3") so I can see where it's installed?

/usr/bin/python is the location for python 2.7, as installed by previous OSs. It isn't installed any more.

If you've installed python3 via brew, its location will depend on whether your machine has an M1 processor. Type which python3 in Terminal to find its location and adjust the path in the shell script to suit.

Thanks, min is in /Library/Frameworks/Python.framework/Versions/3.10/bin/python3. One question I had was, if I type "python" I get an error since it's not installed, though python3 is. Do i need to edit the commands in the Alfred workflow to make them work, since they access "python"? Or is there a binding or something I need to do for the command?

I'll try removing python3 and installing 2.7 and testing again!

No need to uninstall -- you can have python v2.7 and python3 on the same machine.

I'm a bit confused because I see from earlier in the thread that home-brew installed python3 in /opt/homebrew/python3 yet you're getting a different result from which python3. That being /Library/Frameworks suggests you've installed the Xcode command line tools.

If you have then your PATH should be set correctly (it isn't always with a brew install) and you should be able to run python3 without an explicit path. Try python3 --version in Terminal and see if you get anything sensible.

If that works you might be able to simply change the Alfred script line to python3 url_for_image.py "{query}" -- but that assumes there's no python v2.7-only code in the script. But I don't think so -- it looks like there's a script in the Alfred workflow -- you also need to change the first "shebang" line to your python3 path.

Even that may only get you back to the situation 6 posts up, where the python script is running but the AppleScript is complaining of an unmatched double-quote. Did you make any changes to the AppleScript? Have you tried with different images, particularly images with and without space characters in their names (POSIX path of in the AppleScript will escape double-quotes for you, but won't escape spaces, which might be confusing the next step of the workflow -- although in that case I'd expect the py script to error because it checks the number of arguments).

Although I'll admit I'm stabbing in the dark here, not having Alfred and trying to pick up clues from the workflow GitHub sources. There may be other stuff going on in there that I don't know about...