Skip to content

Instantly share code, notes, and snippets.

View SKaplanOfficial's full-sized avatar

Stephen Kaplan SKaplanOfficial

View GitHub Profile
@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:
@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 / 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 / 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 / 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 / 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 / list_textedit_text_elements.py
Last active November 15, 2022 01:31
Using PyXA to list all paragraphs, words, and characters in all currently open TextEdit documents
# Test with PyXA 0.1.0
import PyXA
app = PyXA.Application("TextEdit")
documents = app.documents()
print("Paragraphs:", documents.paragraphs())
print("Words:", documents.words())
print("Characters:", documents.characters())
@SKaplanOfficial
SKaplanOfficial / prepend_date_to_textedit_documents.py
Last active November 15, 2022 01:32
Using PyXA to prepend a date at the beginning of every currently open TextEdit document
# Tested with PyXA 0.1.0
import PyXA
app = PyXA.Application("TextEdit")
documents = app.documents()
date = datetime.now()
documents.prepend(str(date) + "\n\n")
@SKaplanOfficial
SKaplanOfficial / send_sms_to_chat.py
Last active November 15, 2022 01:32
Using PyXA to send an SMS to a chat based on the chat ID
# Tested with PyXA 0.1.0
import PyXA
app = PyXA.Application("Messages")
chat = app.chats().by_id("SMS;-;+11234567891")
chat.send("Hello!")
@SKaplanOfficial
SKaplanOfficial / open_new_safari_tab.py
Last active November 15, 2022 01:33
Using PyXA to open a new tab or window of Safari
# Tested with PyXA 0.1.0
import PyXA
app = PyXA.Application("Safari")
new_tab = app.make("tab", {"URL": "http://google.com"})
app.front_window().tabs().push(new_tab)