Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import errno
  2. import os
  3. import sys
  4. from shlex import quote
  5.  
  6. commands = []
  7.  
  8.  
  9. def quote_shell(args):
  10. return " ".join(quote(arg) for arg in args)
  11.  
  12.  
  13. def quote_applescript(string):
  14. charmap = {"\n": "\\n", "\r": "\\r", "\t": "\\t", '"': '\\"', "\\": "\\\\"}
  15. return '"%s"' % "".join(charmap.get(char, char) for char in string)
  16.  
  17.  
  18. commands.append(
  19. [
  20. "osascript",
  21. "-e",
  22. "do shell script %s "
  23. "with administrator privileges "
  24. "without altering line endings" % quote_applescript(quote_shell(args=[""])),
  25. ]
  26. )
  27.  
  28. for args in commands:
  29. try:
  30. os.execlp(args[0], *args)
  31. except OSError as e:
  32. print(sys.exc_info()[0])
  33. if e.errno != errno.ENOENT or args[0] == "sudo":
  34. raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement