Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine current Mac Safari web page using Python

Is there a way to determine programmatically, using Python, which web page is currently active in Safari?

like image 524
Chris Redford Avatar asked May 13 '26 01:05

Chris Redford


1 Answers

An Applescript example is here, and the relevant part is:

tell application "Safari"
    set url_list to URL of every document
end tell

Python/AppleScript translation is covered here. E.g., install appscript as described here:

sudo easy_install appscript

and then, as shown here, you can do e.g.:

>>> import appscript
>>> print appscript.app("Safari").windows.first.current_tab.URL()
http://wiki.python.org/moin/MacPython/Safari
like image 170
Alex Martelli Avatar answered May 15 '26 16:05

Alex Martelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!