make applescript spawn function more generic