Safari Module Overview
PyXA has full nearly complete feature support for Safari, but some functionalities, such as saving a document, are currently unavailable. These will be implemented in future versions of the Safari module.
Safari Tutorials
There are currently no tutorials for the Safari module.
Safari Examples
The examples below provide an overview of the capabilities of the Safari module. For more in-depth examples that show output and provide more detailed explanations, refer to the previous section (Safari Tutorials).
Example 1 - Using Safari Methods and Attributes
This example provides an overview of the most common methods and attributes of the Safari module.
1import PyXA
2
3# Open URL in new tab
4safari = PyXA.Application("Safari")
5
6# Get open windows, documents, and tabs
7window1 = safari.front_window()
8window2 = safari.windows()[1]
9documents = safari.documents()
10current_doc = safari.current_document
11tabs = window1.tabs()
12current_tab = window1.current_tab
13
14# Get properties of documents
15urls = documents.url()
16names = documents.name()
17html = current_doc.source()
18
19# Get properties of tabs
20urls = tabs.url()
21texts = tabs.text()
22name = current_tab.name()
23
24# Filter documents and tabs
25doc1 = documents.by_url("https://apple.com")
26doc2 = documents.by_name("Apple")
27tab1 = tabs.by_index(1)
28tab2 = tabs.by_visible(True)
29
30# Bulk document operations
31documents.add_to_reading_list()
32documents.email()
33documents.do_javascript("alert('Testing 1 2 3');")
34documents.search("Example")
35
36# Bulk tab operations
37tabs.reload()
38tabs.add_to_reading_list()
39tabs.email()
40tabs.do_javascript("alert('Hello!');")
41tabs.search("Example")
42tabs.move_to(window2)
43tabs.duplicate_to(window2)
44
45# Sub-array operations
46some_tabs = tabs[3:5]
47some_tabs.close()
Safari Resources
For all classes, methods, and inherited members of the Safari module, see the Safari Module Reference.