Ejemplo n.º 1
0
 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.')
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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()
Ejemplo n.º 4
0
 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}"')
Ejemplo n.º 5
0
 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)
Ejemplo n.º 6
0
 def document_name(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return name"))
Ejemplo n.º 7
0
 def document_html(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return source"))
Ejemplo n.º 8
0
 def move_file_to_trash(self, target: str) -> None:
     as_wrapper.tell_app(self.name, f'move POSIX file "{target}" to trash')
Ejemplo n.º 9
0
 def activate(self):
     as_wrapper.tell_app(app=self.name, command="activate")
     if not self.frontmost:
         raise EnvironmentError(f'{self.name} has not activated')
Ejemplo n.º 10
0
 def eject_mounted_disks(self) -> None:
     return as_wrapper.tell_app(
         self.name, "eject (every disk whose ejectable is true)")
Ejemplo n.º 11
0
 def close_windows(self):
     try:
         return as_wrapper.tell_app(self.name, "close every window")
     except AppleScriptError:
         pass
Ejemplo n.º 12
0
 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()
Ejemplo n.º 13
0
 def search_web(self, query: str) -> None:
     as_wrapper.tell_app(self.name,
                         f'tell front tab to search the web for "{query}"')
Ejemplo n.º 14
0
 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}"')
Ejemplo n.º 15
0
 def reveal_pane(self, pane_id="com.apple.preference.security"):
     return as_wrapper.tell_app(self.name, f'reveal pane "{pane_id}"')
Ejemplo n.º 16
0
 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}"')
Ejemplo n.º 17
0
 def authorize(self):
     return as_wrapper.tell_app(self.name, "tell current pane to authorize")
Ejemplo n.º 18
0
 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}"')
Ejemplo n.º 19
0
 def current_pane_id(self):
     return as_wrapper.tell_app(self.name, "return id of current pane")
Ejemplo n.º 20
0
 def pane_ids(self) -> List[str]:
     return as_wrapper.tell_app(self.name, "return id of every pane")
Ejemplo n.º 21
0
 def document_url(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return URL"))
Ejemplo n.º 22
0
 def window_path(self) -> str:
     return as_wrapper.tell_app(
         self.name,
         "return POSIX path of (target of first window as alias)")