Tip/Trick: using scripting to make an animated GIF

I used it just the other day to create my first animated GIF with the new ScreenFlow.  For other people made a quick "making of" video - have shared it here in case it inspires anyone else.

You can see the script I used to automate Numbers. From there was able to record it and crop it as I wanted... and add an overlay to get rid of the "120%" line, fade from one clip to the next, change the speed to 400%, etc. All the easy goodies I am very thankful to have ScreenFlow for. 

2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • sancarn
    • sancarn
    • 6 yrs ago
    • Reported - view

    I created a similar thing to you myself recently.

    In this case I used Excel's VBA to animate the objects. I recorded it on OBS on a windows machine (Excel animations don't appear to work so well on Excel for Mac...) and then animated the animations further in Screenflow.


    Here is the code I used for the bar chart:

    #If VBA7 Then
        Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
        Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
    #End If

    Public Sub percentageGrow(cell As Range, maxPercent As Double, Optional steps As Double = 1)
        cell.Value = 0
        For i = 0 To maxPercent Step steps
            cell.Value = i / 100
            Application.ScreenUpdating = True
            Sleep fCurve(i, maxPercent) * 50
        Next i

    cell.Value = maxPercent / 100

    End Sub

    Function tanh(ByVal x As Double)
        tanh = Application.WorksheetFunction.tanh(x)
    End Function

    Function fCurve(ByVal x As Double, ByVal m As Double)
        fCurve = (tanh(4 * x / m - 2) + 1) / 2
    End Function

    Sub AnimatePie()
        percentageGrow Range("E19"), 20, 0.1
    End Sub

    Sub AnimateBars()  
        percentageGrow Range("D1"), 100, 1
    End Sub


    On Mac the percentageGrow function will have to be a lot simpler since the sleep() function is a pre-requisite of the Windows System32 APIs (kernel32 specifically). Also from experience Charts in Excel for Mac do not appear to visually update after a DoEvents call. It might require multiple DoEvents calls or a completely seperate call all together. So even if you comment out the line "Sleep fCurve(i, maxPercent) * 50" the code will still not animate the charts.


    However if you have a Windows PC you can use the code "out of the box" as it were.


    The use of fCurve is simply to get a "ease in, ease out" effect. I should have made that an external call in hindsight, so you could set the function to animate on and then play the animation.


    The subroutine "percentageGrow" simply counts up in a cell provided. so for instance "percentageGrow Range("D1"), 100, 1", will count up in cell D1 from 0 to 100, 1 at a time. Where as "percentageGrow Range("E19"), 20, 0.1" will count up in cell E19 from 0 to 20, 0.1 at a time. Ultimately the syntax is:


    percentageGrow <cell>, <maximumPercentage>,<stepSize>


    Finally it is worth noting that since VBA isn't multithreaded you can only alter the value of 1 cell at a time. For this reason, to control the other values we need to use formula.


    Or in the case of the bar chart:



    Hope this helps! :)

    • Michael Glasser
    • Prescott Computer Guy
    • Michael_Glasser
    • 6 yrs ago
    • Reported - view

    Thanks. Interesting to see how different people approach similar tasks.

    Out of curiosity I tried to replicate the idea of yours, but with the style closer to what I had before, done in Numbers. 


    I used a "set" field and (basically) the same script as I used above (had to reset the mouse coordinates).

    • The "set" field goes from 0.00% to 0.10% by increments of 0.01
    • The others in that table are set to "set" x 11, 22, and 67. This does not create the ease in, ease out growth, though I suppose I could have come up with a formula to do so.
    • For the other table the top is (1 - "set" x 20) so it goes from 100% down to 80% and the bottom is just (1 - top). 

    My first recording of it was done when there was a Time Machine backup and it "stuttered" some - maybe because of the multiple calculations (though they are not really that complex!). The second recording went fine.

    Brought it into ScreenFlow (hey, in a ScreenFlow forum I should get around to showing how it was involved!)

    With that it was easy to crop the clip by time and canvas size and set the speed to what I wanted (watching it now I think too fast, but just did this quickly to see if I could). I then pulled in a second copy of the same media and showed the other chart. 

    Then I used, again, the same media to show the "making of" section.

    I am sure this is not the norm for how ScreenFlow is used... showing the same clip with different crops and different speeds - but to the credit of the developers it is was all very easy. 

    Thanks ScreenFlow team! :)

    Like 2
Like1 Follow
  • 6 yrs agoLast active
  • 2Replies
  • 820Views
  • 3 Following