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