Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@SKaplanOfficial
SKaplanOfficial / count_shortcuts.py
Last active September 15, 2023 16:22
Using PyXA to get the number of shortcuts in each shortcuts folder
# Tested with PyXA 0.1.0
import PyXA
app = PyXA.Application("Shortcuts")
folders = app.folders()
# Method 1 - Standard iteration
summary = []
for folder in folders:
folder_name = folder.name
num_shortcuts = len(folder.shortcuts())
@SKaplanOfficial
SKaplanOfficial / shortcut_url_input.py
Last active November 12, 2022 07:31
Using PyXA to run a shortcut with the URL of a Safari tab as input
# Tested with PyXA 0.1.0
import PyXA
shortcuts = PyXA.Application("Shortcuts")
safari = PyXA.Application("Safari")
document = safari.current_document
shortcut = shortcuts.shortcuts().by_name("Save As PDF")
shortcut.run(document.url)
@SKaplanOfficial
SKaplanOfficial / authenticate_system_preferences.py
Last active November 12, 2022 08:04
Using PyXA to reveal a System Preferences pane and prompt for authorization
# Tested with PyXA 0.1.0
import PyXA
from time import sleep
app = PyXA.Application("System Preferences")
app.activate()
pane = app.panes().by_name("Date & Time")
pane.reveal()
sleep(0.5) # Wait for animation to finish
pane.authorize()
@SKaplanOfficial
SKaplanOfficial / save_textedit_documents.py
Last active November 12, 2022 08:11
Save all currently open TextEdit documents with PyXA
# Tested with PyXA 0.1.0
import PyXA
app = PyXA.Application("TextEdit")
for doc in app.documents():
doc.save()
@SKaplanOfficial
SKaplanOfficial / print_textedit_document.py
Last active November 12, 2022 08:15
Printing a TextEdit document with print settings in PyXA
# Tested with PyXA 0.1.0
import PyXA
from datetime import datetime, timedelta
app = PyXA.Application("TextEdit")
doc = app.documents()[0]
print_time = datetime.now() + timedelta(minutes=1)
properties = {
"copies": 3,
"collating": False,
"startingPage": 1,
@SKaplanOfficial
SKaplanOfficial / finder_window_controller.py
Created June 22, 2022 06:33
Setting the bounds of a Finder window with PyXA
import PyXA
app = PyXA.application("Finder")
window = app.windows()[0]
lock = False
old_w = 0
old_h = 0
while True:
if window.position.y < 50 and lock is False: