def getTextFromDialog(): textOfMyScript = """ tell application "System Events" set myWords to "This PDF is protected" & return & "Please enter the password:"******"Encrypted PDF" default answer "" buttons {"Cancel", "Continue"} default button 2 with icon 0 with hidden answer) end tell """ myScript = NSAppleScript.initWithSource_(NSAppleScript.alloc(), textOfMyScript) results, err = myScript.executeAndReturnError_(None) # results is an NSAppleEventDescriptor, which describes two things: # The button pressed (1), and the text returned (2). if not err: try: returnedInput = results.descriptorAtIndex_(2).stringValue() except: return None else: if returnedInput: return returnedInput else: return None else: print(err) return None
def getTextFromDialog(): textOfMyScript = """ tell application "System Events" set myWords to "This PDF is protected" & return & "Please enter the password:"******"Encrypted PDF" default answer "" buttons {"Cancel", "Continue"} default button 2 with icon 0 with hidden answer) end tell """ myScript = NSAppleScript.initWithSource_(NSAppleScript.alloc(), textOfMyScript) results, err = myScript.executeAndReturnError_(None) # results is an NSAppleEventDescriptor, which describes two things: # The button pressed (1), and the text returned (2). if not err: try: returnedInput = results.descriptorAtIndex_(2).stringValue() except: return None else: if returnedInput: return returnedInput else: return None else: print err return None
def get_browsers_tab(self): """ :return: the representation of current url """ text_of_my_script = """tell app "google chrome" to get the url of the active tab of window 1""" s = NSAppleScript.initWithSource_( NSAppleScript.alloc(), text_of_my_script) results, err = s.executeAndReturnError_(None) web_page_info = results.stringValue() return 'Web browser: {}'.format(web_page_info)