I save a lot of gifs.
I used to store them in Dropbox and share them with a link, but Dropbox has changed the way they handle Public folders and links, so it was a hassle to drop a gif in. Plus, I'm trying to migrate my stuff away from big services in 2019 (more coming this in a future post!) With this in mind, a week or two ago I setup a nice little Alfred workflow for to grab the links to my gifs and share them.
First things first, I had to set up my gif hosting. I use NearlyFreeSpeech to host my personal site. I store the gifs in a folder in there and sync them back and forth using rsync. Basically all you need for this step is a publicly hosted base url for your gifs - i.e. https://wuz.fyi/gifs for my site.
Now that you have that, let's set up a new alfred workflow. Open up your Alfred preferences and head over to the Workflows tab:
Click the little plus in the bottom of the sidebar and click Blank Workflow:
Give your workflow a name, description, and any other info you want to give it.
Once that is done, right click in the black area to add a workflow object and select Inputs > File Filter. Give your filter a keyword, some placeholder text. Then drag and drop the types of files you want to search into the File Types section. For me that is gifs, pngs, and jpegs:
Now, click on over to the Search Scope tab and drag and drop your gif folder:
Save that and let's move on! Right click again and select Actions > Run Script. Once that opens, change "with input as argv" to "with input as {query}" and paste this code:
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
}
URL="https://wuz.fyi/gifs/"
echo -ne "${URL}$(urlencode "$(basename {query})")" | pbcopy
Be sure to check every checkbox at the bottom, besides "Backslashes". You'll also want to set URL
to wherever you are hosting your gifs.
If this is all right, you should be able to open up Alfred, type your keyword followed by a gif title (i.e. gifit awesome.gif
) and hit enter. Your clipboard should have the gif you want! Try pasting and make sure it all works!
Way to go! I hope you get as much enjoyment and usage out of this as I have!
Help me spend too much money on hosting! What is your favorite gif? Share below!
Top comments (0)