I am not really familiar with syncing in calibre, because the closed nature of kindle and the inability to manage collections, means it is better for me to just email one book at a time. But in principle, that code above could be adapted to a custom action or a "Run Python Code" action. For anyone interested, to halt the chain, instead of returning the function, you should call:
Code:
raise chain.UserInterrupt