Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import errno
- import os
- import sys
- from shlex import quote
- commands = []
- def quote_shell(args):
- return " ".join(quote(arg) for arg in args)
- def quote_applescript(string):
- charmap = {"\n": "\\n", "\r": "\\r", "\t": "\\t", '"': '\\"', "\\": "\\\\"}
- return '"%s"' % "".join(charmap.get(char, char) for char in string)
- commands.append(
- [
- "osascript",
- "-e",
- "do shell script %s "
- "with administrator privileges "
- "without altering line endings" % quote_applescript(quote_shell(args=[""])),
- ]
- )
- for args in commands:
- try:
- os.execlp(args[0], *args)
- except OSError as e:
- print(sys.exc_info()[0])
- if e.errno != errno.ENOENT or args[0] == "sudo":
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement