Jump to content

GIF Search: Workflow for Searching and Browsing GIFs


Recommended Posts

54 minutes ago, Mr Pennyworth said:

whether the problem could be because of BigSur

 

It doesn’t work on my Catalina machine, either. gif-downloader.bin downloads the GIFs, but it always returns the same response:

 

{"items":[{"arg":"dummy","valid":true,"title":"Select with arrow keys, drag-n-drop with mouse","subtitle":"[↩: search again] [⌘: copy GIF] [⌥: copy URL]","gifHtml":"/Users/daj/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/mr.pennyworth.gif/scream-gifs.html.html"}]}

 

(Ignore the mojibake: it's just because the server isn't sending a Content-Type header. The JSON is valid.)

Link to comment

@deanishe
Haha I'm so embarrassed right now! 🙈

 

I'm doing things in a very convoluted manner :(

For each response the `gifHtml` part is different. For example, you searched for "scream", so it created `scream-gifs.html.html` (meaning to delete that double extension too 🤣)

  1. That response is then piped into a python script.
  2. The python script creates css that matches alfred's theme and then sends the html from (1) and this css to the swift app
  3. The swift app displays injects the css into the html, and displays this injected html in a webview

 

10 minutes ago, deanishe said:

but it always returns the same response:

TL;DR: the json is not the same, as the html filename is query-specific

 

What I presently can't seem to figure out is why the swift app never displays the webview for both you and @Miteg !

Link to comment
32 minutes ago, Mr Pennyworth said:

the json is not the same, as the html filename is query-specific

 

I understand the filename changes, but shouldn't there be some search results for Alfred somewhere in there, too? The workflow never shows any results in Alfred, just "Select with arrow keys, drag-n-drop with mouse". I presume that's referring to Alfred's list of results?

Link to comment
5 minutes ago, deanishe said:

I understand the filename changes, but shouldn't there be some search results for Alfred somewhere in there, too? The workflow never shows any results in Alfred, just "Select with arrow keys, drag-n-drop with mouse". I presume that's referring to Alfred's list of results?

That's where the convoluted-ness of it all comes in.

Alfred has only one result (the one seen is json).

 

43 minutes ago, Mr Pennyworth said:

The swift app displays injects the css into the html, and displays this injected html in a webview

This same swift app watches for keystrokes and mouse movements and passes them along to the webview. The webview accordingly highlights the corresponding GIF. Similarly, the swift app is responsible for the drag-and-drop functionality.

 

Alfred never really sees all the GIF urls, or any other result list. He only sees one single html file.

Here's the same HTML file opened in safari:

image.thumb.png.b1441d6877e543f4534889c345b2af26.png

 

In this whole thing, alfred acts as

  1. a text-input box for the query
  2. a platform (the workflow editor) that allows me to stitch multiple hodge-podge scripts to get the final thing working

image.png.1adf66c2a4e9c1ef53394e15f770a8bf.png

Link to comment
5 minutes ago, deanishe said:

What do "⌘: copy GIF" and "⌥: copy URL" mean, then?

Both act on the "highlighted GIF"

image.png.a2da2b6cdc98da962da6ccb9a0552670.png

When the user presses cmd-enter, the highlighted GIF file gets copied to the clipboard (pasteboard data type public.file-url). In this case, if the user goes to finder, and hits cmd-v, a GIF file will appear in that folder.


When the user presses option-enter, the web url of the highlighted GIF gets copied to the clipboard (pasteboard data type public.utf8-plain-text). In this case, if the user goes to any text editor, and hits cmd-v, a link like this will be pasted there: https://c.tenor.com/tVoDE6m_A0QAAAAM/jonah-hill-shriek.gif.

 

You may ask who does the copying and option/cmd distinguishing etc. Again, the swift app. At this point, it feels like "why not spin out a separate app instead of an alfred workflow?" doesn't it? 🙈

 

Look at the corresponding swift code:

image.thumb.png.b5cb71c94057a19e596ee0e05aff5280.png

 

Link to comment
1 hour ago, Mr Pennyworth said:

pasteboard data type public.utf8-plain-text

 

Wouldn’t public.url be more appropriate?

 

Out of interest, why did you write the app in Swift, but the HTTP server in JS? That thing is 35MB.

Edited by deanishe
Link to comment
12 minutes ago, deanishe said:

Wouldn’t public.url be more appropriate?

Yep! I should change that :)

 

13 minutes ago, deanishe said:

Out of interest, why did you write the app in Swift, but the HTTP server in JS?

Laziness and reluctance to learn swift.


I have very little understanding of swift. Wrote only those things in swift, which felt like very difficult to write in other languages I know (Scala, Javascript, Python).

 

Even the bundled python scripts in the swift app could be written in swift.

 

Every once in while I get the enthusiasm: "lemme get rid of the huge JS dist, and go with a swift program instead"
And it dies down quickly: "but it works" :(

 

 

Link to comment

I'm not sure if my issue is similar to Miteg's, but I'm not getting any results from the workflow. I've installed it, and run the setup command (/tmp/alfred-gif-search.log). On my Intel iMac, AlfredGifBrowser never self-populated in Accessibility>Privacy, so I manually dragged it in from the workflow package contents. On my M1 Mac Mini , it did appear there automatically, so I only needed to check the box. But on both Macs, I type gif followed by a search query, and it re-loops back to the search box without showing any previews.

 

I'm ignorant about this sort of thing. Could a content blocker in Safari affect things?

Link to comment
4 hours ago, Cyberskier said:

and run the setup command (/tmp/alfred-gif-search.log).

That's not the setup command though.

After you download and import the workflow into alfred, you need to open alfred and type .setup-gif-search.

 

Also, can you make sure that you area either using a custom theme for alfred, or, if not, then using a duplicated version of a built-in theme?

 

Do not use any of these:
image.thumb.png.2e6bbf333517c8b6133d68b0923b8ba6.png

 

Here's how you can duplicate:

Right-click on the theme name:

image.png.a2c35b8332563632d1cb16485a953bbc.png

Link to comment

I'm not getting any query results so far.  When I look in /tmp/alfred-gif-search.log I see this:

 

Responded to alfred from cache
URLSearchParams { 'query' => 'stuff' }
response.setHeader is not a function
/Users/jakes/Library/Caches/com.runningwithcrayons.Alfred/Workflow Data/mr.pennyworth.gif/stuff-gifs.html already cached

 

I am running node v16.0, installed via homebrew.  Any ideas what's wrong?

Edited by JakeS
Link to comment
On 5/24/2021 at 9:36 PM, Mr Pennyworth said:

That's not the setup command though.

After you download and import the workflow into alfred, you need to open alfred and type .setup-gif-search.

 

Also, can you make sure that you area either using a custom theme for alfred, or, if not, then using a duplicated version of a built-in theme?

 

Oops, that was a typo, pasting the wrong thing from my clipboard manager after checking the log. I've run .setup-gif-search and changed to a duplicated/custom theme, and things now work great on my Intel iMac, but still not working on my M1 MacBook Pro. Everything appears the same (Accessibility properly set up), so I'm a bit baffled as to the issue.

Link to comment

@Cyberskier apologies! The workflow right now doesn't support M1, and I'm not sure how much of a work it would be to support it. :(

 

Technical details if curious:

The workflow ships with compiled binaries (an entire nodejs runtime and a swift app).

As they aren't universal binaries, it won't work on an M1 mac.

I'm working on getting rid of nodejs right now.

After that, I'll look into making the swift app universal.

Link to comment
6 hours ago, Mr Pennyworth said:

@Cyberskier @JakeS could you try the latest release and see if works on M1 macs?

(I don't have access to an M1 mac)

 

I'm afraid it still doesn't show actual results for me.

 

`/tmp/alfred-gif-search.log` has no new entries though, and has not been touched since in the last two days, so there's not a lot of feedback to give.

 

When searching, it does switch the label to say "select with arrow keys..." etc.

 

If there's somewhere else I can look for logs or help troubleshoot I'm happy to.  I also have Xcode.  Never worked with Swift myself, but how hard can it be? :)

Link to comment
4 hours ago, JakeS said:

If there's somewhere else I can look for logs or help troubleshoot I'm happy to.  I also have Xcode.  Never worked with Swift myself, but how hard can it be? :)

Not having the logs sucks :(

 

You can run the following in the terminal, and then use the workflow. That way, you can see the logs in the terminal in real time.

killall AlfredGifBrowser; ./AlfredGifBrowser.app/Contents/MacOS/AlfredGifBrowser

 

 

Link to comment
19 minutes ago, Mr Pennyworth said:

Not having the logs sucks :(

Well that shows it IS finding lots of matching images, cataloging them, and caching them.

 

alfred: ScriptFilterResponse(items: [Alfred.ScriptFilterResponse.Item(arg: "dummy", uid: nil, title: "Select with arrow keys, drag-n-drop with mouse", subtitle: Optional("[↩: search again] [⌘: copy GIF] [⌥: copy URL]"), valid: nil, match: nil, autocomplete: nil, quicklookurl: nil, type: nil, text: nil, icon: nil, mods: nil)])
2021-05-28 13:30:12.264 AlfredGifBrowser[7397:4565081] [WebViewCache.swift:79 startCacheDirWatcher()] Adding to cache due to FS change: 1B76D167EC3A8E056B9CE1040662B00BE99E1229)
2021-05-28 13:30:12.264 AlfredGifBrowser[7397:4565081] [WebViewCache.swift:38 addToDict(recordFileURL:)] Web URL in cache: https://c.tenor.com/7I9nkd071vYAAAAM/food-coma-food.gif
2021-05-28 13:30:12.264 AlfredGifBrowser[7397:4565081] [WebViewCache.swift:44 addToDict(recordFileURL:)] Cache dict size: 385

 

Lots more results like these (after the line that sets the Alfred response), but no error or indication of why the view itself isn't showing.

Edited by JakeS
Link to comment

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...