Skip to content

Instantly share code, notes, and snippets.

@marceloneppel
Forked from SKaplanOfficial/saved_current_url.py
Created September 15, 2023 16:22
Show Gist options
  • Save marceloneppel/7d73ee79b6b83aadb69d03a7abd2ce34 to your computer and use it in GitHub Desktop.
Save marceloneppel/7d73ee79b6b83aadb69d03a7abd2ce34 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