Пример #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.')
Пример #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)
Пример #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()
Пример #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}"')
Пример #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)
Пример #6
0
 def document_name(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return name"))
Пример #7
0
 def document_html(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return source"))
Пример #8
0
 def move_file_to_trash(self, target: str) -> None:
     as_wrapper.tell_app(self.name, f'move POSIX file "{target}" to trash')
Пример #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')
Пример #10
0
 def eject_mounted_disks(self) -> None:
     return as_wrapper.tell_app(
         self.name, "eject (every disk whose ejectable is true)")
Пример #11
0
 def close_windows(self):
     try:
         return as_wrapper.tell_app(self.name, "close every window")
     except AppleScriptError:
         pass
Пример #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()
Пример #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}"')
Пример #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}"')
Пример #15
0
 def reveal_pane(self, pane_id="com.apple.preference.security"):
     return as_wrapper.tell_app(self.name, f'reveal pane "{pane_id}"')
Пример #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}"')
Пример #17
0
 def authorize(self):
     return as_wrapper.tell_app(self.name, "tell current pane to authorize")
Пример #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}"')
Пример #19
0
 def current_pane_id(self):
     return as_wrapper.tell_app(self.name, "return id of current pane")
Пример #20
0
 def pane_ids(self) -> List[str]:
     return as_wrapper.tell_app(self.name, "return id of every pane")
Пример #21
0
 def document_url(self) -> str:
     return str(
         as_wrapper.tell_app(self.name,
                             "tell front document to return URL"))
Пример #22
0
 def window_path(self) -> str:
     return as_wrapper.tell_app(
         self.name,
         "return POSIX path of (target of first window as alias)")