just a copy of some stuff in https://github.com/codepill/script-utilities