Trying to use the following code (which works fine in applescript) to work in Python , fairly new to Python so I am not sure how I can get this string to work properly.
def getChromeSource():
cmdGetSource = """
osascript -e 'tell application "Google Chrome" to set source to execute front window's active tab javascript "document.documentElement.outerHTML"'
"""
proc = subprocess.Popen([cmdGetSource], stdout=subprocess.PIPE, shell=True)
(source, err) = proc.communicate()
I am confident the problem is with
window's
I have tried:
window\s
but that doesn't work I think I just have too many quotation marks and I am not sure how to write the string correctly, probably a really easy one so hopefully someone can steer me in the right direction.
You should pass the list of arguments you want to execute rather than creating a string with all the arguments put together. You also shouldn't use the shell=true
flag.
cmd_args = ['osascript', '-e', 'tell application "Google Chrome" to set source to execute front window\'s active tab javascript "document.documentElement.outerHTML"']
proc = subprocess.Popen(cmd_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
source, err = proc.communicate()