def quit(self, pause: Union[int, float] = 2) -> None: time.sleep(pause) as_wrapper.tell_app(self.name, "quit", ignoring_responses=True) if not macos.service_manager.wait_process_disappeared(self.name): macos.service_manager.kill_process(self.name) if not self.did_quit: raise EnvironmentError(f'{self.name} has not quit.')
def close_tabs(self): if not self.is_running: return try: as_wrapper.tell_app(self.name, "close tabs of every window", ignoring_responses=True) wait_condition(lambda: as_wrapper.tell_app( self.name, "return the number of tabs in windows") == 0) except AssertionError: as_wrapper.tell_app(self.name, "close every window", ignoring_responses=True)
def current_pane_anchors(self) -> List[str]: try: return as_wrapper.tell_app( self.name, "return name of every anchor of current pane") except AppleScriptError: logging.warning("You must launch System Preferences first.") return list()
def execute_js_command(self, command: str): command = command.replace('"', '\\"') tell_what = f'tell front document to do JavaScript "{command}"' try: return as_wrapper.tell_app(self.name, tell_what) except AppleScriptError: logging.warning(f'Could not execute: "{tell_what}"')
def request_webpage(self, url: str): as_wrapper.tell_app( self.name, f'make new document with properties {{URL:"{url}"}}') wait_condition(lambda: self.native_window is not None)
def document_name(self) -> str: return str( as_wrapper.tell_app(self.name, "tell front document to return name"))
def document_html(self) -> str: return str( as_wrapper.tell_app(self.name, "tell front document to return source"))
def move_file_to_trash(self, target: str) -> None: as_wrapper.tell_app(self.name, f'move POSIX file "{target}" to trash')
def activate(self): as_wrapper.tell_app(app=self.name, command="activate") if not self.frontmost: raise EnvironmentError(f'{self.name} has not activated')
def eject_mounted_disks(self) -> None: return as_wrapper.tell_app( self.name, "eject (every disk whose ejectable is true)")
def close_windows(self): try: return as_wrapper.tell_app(self.name, "close every window") except AppleScriptError: pass
def show_destination(self, destination: str) -> None: if not os.path.exists(destination): raise FileNotFoundError(destination) as_wrapper.tell_app(self.name, f'reveal POSIX file "{destination}"') self.window.wait_displayed() self.activate()
def search_web(self, query: str) -> None: as_wrapper.tell_app(self.name, f'tell front tab to search the web for "{query}"')
def get_pane_anchors(self, pane_id: str) -> List[str]: return as_wrapper.tell_app( self.name, f'return name of every anchor of pane "{pane_id}"')
def reveal_pane(self, pane_id="com.apple.preference.security"): return as_wrapper.tell_app(self.name, f'reveal pane "{pane_id}"')
def show_anchor(self, anchor: str, pane_id="com.apple.preference.security"): return as_wrapper.tell_app( self.name, f'reveal anchor "{anchor}" of pane "{pane_id}"')
def authorize(self): return as_wrapper.tell_app(self.name, "tell current pane to authorize")
def open_destination(self, destination: str) -> None: if not os.path.exists(destination): raise FileNotFoundError(destination) as_wrapper.tell_app(self.name, f'open POSIX file "{destination}"')
def current_pane_id(self): return as_wrapper.tell_app(self.name, "return id of current pane")
def pane_ids(self) -> List[str]: return as_wrapper.tell_app(self.name, "return id of every pane")
def document_url(self) -> str: return str( as_wrapper.tell_app(self.name, "tell front document to return URL"))
def window_path(self) -> str: return as_wrapper.tell_app( self.name, "return POSIX path of (target of first window as alias)")