Address List scripting?

I have a question concerning address lists and scripting:
I would like to have a script (that runs manually) that checks the count of the number of addresses in an address list. Once it reaches a certain count I want to disable adding new addresses. (I am using mangle to add addresses to an address list based on protocol/port)

Is there an example of this? Or can someone point me in the right direction? (I am new to scription on MikroTik - I have RouterOS 3.19)

Try this.

:global addresscount [/ip firewall address-list print count-only]
:local maxcount 10

:if ( $addresscount > $maxcount ) do={
    /ip firewall mangle disable [/ip firewall mangle find comment="addresslist"]
} else={
    /ip firewall mangle enable [/ip firewall mangle find comment="addresslist"]
}

Add the comment “addresslist” to the mangle rule that adds to the address-list. It is now set to disable the rule at 11 address-list entries, then enable it again at 10 or below.
My apology for any typos.

Thank you for the reply SurferTim!

Is there a way to have this script run all the time? Or as part of a mangle rule (or enable/disable the script when needed)?

You can schedule the script to run at specific times with the scheduler.
/system scheduler
add name=addlist on-event=addlist start-time=12:00:00 interval=1h

I used the script name addlist, but you can change that to your preference. This starts running the script at noon and runs it every hour after that. You can change both those also. See the docs under Scheduler for more.