Skip to content

Instantly share code, notes, and snippets.

@SKaplanOfficial
Last active September 15, 2023 16:22
Show Gist options
  • Save SKaplanOfficial/d0635c9667703de8dd0db43cbbd857b3 to your computer and use it in GitHub Desktop.
Save SKaplanOfficial/d0635c9667703de8dd0db43cbbd857b3 to your computer and use it in GitHub Desktop.
PyXA script to save the current Safari tab's URL to a "Saved URLs" note
#!/usr/bin/env python
# Test with PyXA 0.1.0
import PyXA
safari = PyXA.Application("Safari")
notes = PyXA.Application("Notes")
# Get info for current Safari tab
current_tab = safari.front_window.current_tab
current_name = "\n" + current_tab.name
current_url = "\n<a href=" + str(current_tab.url) + ">" + str(current_tab.url) + "</a>"
note = notes.notes().by_name("Saved URLs")
if note is None:
# Create new note
notes.new_note("Saved URLs", current_name + current_url)
else:
# Append to existing note
note.set_property("body", note.body + "<br/>" + current_name + "<br/>" + current_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment