Use Gifski (Homebrew Package) to Convert a Video File to a Gif Image

Howdy folks, I've been trying to learn some how to work with shell scripts lately, so I've been making great use of Homebrew packages to make some basic macros.

My latest one is designed to use Gifski (a Homebrew package) to convert video files to gif images. I have been using it for a few days now to convert screen recordings of my other macros to the gif format so I can upload them to the forum here. There is also a GUI application that I used before, and while it has certain advantages (like estimating the file size), I prefer this to be as automated as possible.

No screen recording of this one as it's all done in the background.

While the macro works quite well for me (and why I posted it here, and not in the Questions and Suggestions category), I'm still interested in everybody's thoughts and ideas if this macro can be improved. Thanks in advance, and if this macro proves useful to anybody else then enjoy!

NOTE: This macro has special requirements to run

This macro makes use of the following KM version 10 action(s):
Display progress bar
Position next engine window
If you are running a previous version of KM, simply disable or remove said action(s).

This macro requires Homebrew to be installed. Click the link for more info.

This macro requires Gifski (a Homebrew package) to be installed. Click the link for more info.

This macro requires the end-user to set a ENV_PATH variable (or specify the path in the shell script). Click the link for more info.

CURRENT VERSION: 1.1 (Monday, January 24, 2022)

v1.1: Fixed an issue with the order of the options in the initial prompt action.


04)[AS-F] Images- create gif from video.kmmacros (19 KB)

Macro screenshot (click to expand/collapse)

1 Like

Thanks for sharing this! I have gifski CLI installed (and working), but apparently not where the Execute Shell Action is looking for it:

/var/folders/24/g_by4bn57x5890wq070h323m0000gn/T/Keyboard-Maestro-Script-2C371465-7083-488C-A621-DD17B3F500A8: line 1: gifski: command not found

Hi Evan, that might have to do with KM needing to know where the scripts are installed . if you’re running 3rd party shell scripts from within KM you need to setup an ENV_PATH variable.

Run this script in Terminal:

echo $PATH | sed 's/:/\n/g'

The results will be the folders that you have scripts installed. Put each one of those lines into a variable named ENV_PATH and separate them using a colon :.

On my iMac, Terminal returns the following:


and my KM variable looks like this (it has some extra paths because it's a combination of my iMac and MacBook paths).

1 Like

That did it :+1:

Now it works if I manually enter the Width and FPS. Otherwise, if leave at default or make any selection from the dropdown I get:

error: The argument '--fps <num>' requires a value but none was supplied

I don't have time at the moment to look into further, just wanted to give you a heads up.


Probably because KM gives preference to the manually typed entry over the dropdown selections. I thought that it would still use the dropdown selections but perhaps I didn't set up properly the prompt action. For the time being you could just remove those two manual entry lines. I'll work on this and post an updated version shortly.

Thanks for the heads up!!

EDIT: @evanfuchs apparently I put the options in the wrong order in the prompt action. :man_facepalming: That's what I get for adding a "simple" feature and not testing it before uploading :laughing: See my initial post for version 1.1.

Here's my error:

% gifski --help

dyld[9457]: Library not loaded: /usr/local/opt/ffmpeg/lib/libavutil.56.dylib

I have the latest ffmpeg --HEAD installed using Homebrew. Any ideas? Thanks.

Hmm.... my only real suggestion (because I'm pretty new to shell scripts) is to run the following command from Terminal:

brew doctor

That should let you know what issues there are and give you options to fix it. Let me know what it says and we can go from there.

But I also did a Google search with the error you posted and came across this page on GitHub of somebody who had the same issue and one of the first replies had a solution that worked for the OP.

OK I reversed them and it accepted the dropdown! :partying_face:

Of course that means the blanks are always overwritten by the dropdown, so there may need to be some testing if you want to keep both options. Or maybe a checkmark to indicate custom settings?

Either way, this is a handy macro and it demonstrates some useful approaches. Dig it!

I actually fixed that as well with version 1.1 which is in my initial post. :wink:

Thank you very much for your feedback and willingness to test it! You helped me polish it :grin:

1 Like

Thanks. I didn't expect that to work, because I originally installed it using Homebrew, and not until after I saw your macro post. But sometimes the versions cross in the ether, so I tried "brew reinstall gifski", but that didn't work. I made copies of the later versions of the aliases in the ffmpeg lib folder and gave them the names listed in the error messages (yeah, that's hacking), but it must not be compatible, because then I ended up with the abort 6 trap. It'll be updated eventually, and I'll try it again.

Ah man I'm sorry that didn't work for you! To be honest it sounds like your knowledge of shell scripts and Homebrew is quite beyond mine so I'm not sure what else to do to help. :frowning:

But please do post when you're able to figure it out in case anybody else runs into a similar issue!

No worries, it's still a great macro! And Gif Brewery 3 still works fine when I need it. Thanks!

1 Like

Would you be willing to help me track the variables in this shortcut? I don't understand why, I guess it's just my memory, but I can't seem to string together the realized contents of the variables. I'm not even able to view the variables' values in the Inspector, and I'm confused about why. I've used both """, "%" but no success. I thought it would be related to tokens vs. variables, but no.

I'm able to use Gifski without error when running a command according to its man entry in Terminal, but your shortcut still fails with references to libraries, so I want to see the actual command that's being constructed. I've managed this before quite easily with other commands in KM editor, but there must be something about the way KM editor works that is contrary to my approach, because if I leave it for a week or two then come back, I'm simply vacant. Thanks.

Yea no problem! Let me take a look at it and get back to you shortly. FWIW, all the variables are local so they will not show up in the Values Inspector.

EDIT: @Lantro please place this group of actions above the shell script (and ideally just disable the shell script for the time being).

They will set your clipboard to the complete shell script string as well as display it in a window.

Debugging options for Gifski ideo to GIF conversion macro (for Lantro).kmmacros (3.9 KB)

Macro screenshot (click to expand/collapse)

On another note, whenever I am building and/or debugging a macro, I use global variables prepended with debug__ that way I can see them in real-time in the Value Inspector.

If you're interested, I have a macro set that will automatically populate the VI with any variables used in a macro that @coordinated and I corroborated on a month or so ago. Here's the link to the topic we were discussing it on. I'm not sure of the current status of the macro in post 1, but the last refinements I made to my personal copy (which are in the last post, that's linked to below) have proven to be rock solid.

1 Like

Thanks. That looks exactly like one of the macros I created. I'll try again.

1 Like

OK, this is what your macro generated for me:
gifski --fps 12 --width 320 -o ~/Desktop/moviedesktop.gif~/Desktop/

This is the command line that worked:
gifski -r 12 -W 320 -o ~/Desktop/moviedesktop.gif ~/Desktop/

I substituted the path designation of course, but it's exactly the same for all occurrences. Notice the single space needed between the two paths. Noticed the case sensitive, single letter options. I can send the reconstructed macro if you like. Thanks again.


1 Like

Ah ok, I might know what the issue is. Is that the file path the debug group outputs? If so you may need to remove the tilde from the file path. I thought I had an optional action in there to do that if necessary, but perhaps not. Let me double check real quick.

EDIT: I removed that action apparently. I won't have time to look at it any more tonight but I'll jump on it again in the morning.

No problem.

No, I adjusted the paths (inserted the tllde instead of the spelled out home folder), but made the same adjustment to each occurrence. Your output was correct regarding basic path, it's the other stuff that gifski didn't like.

Uh-oh, one thing I left out: Sandboxing. You must preface the executable name with the full path to the executable. If it's installed by Homebrew in the land of arch -x86_64, it's probably "/usr/local/bin/gifski". If it's distilled along with that new, strange brew, it's probably "/opt/homebrew/bin/gifski". May require checking between the two or even more if there's an another compiled version. The "which" command should help. (It's a good "which", not "whick-ed".)

Is that not something that is accomplished by setting the ENV_PATH variable?