I need to read opened tabs URL in Safari, Chrome and Firefox (optionally) and turn them into an array. I'm using Titanium Appcelerator to develop a Dektop Application, and it support Python.
It can be also done by calling an AppleScript that return what I'm looking for. For example this simple AppleScript show what I'm looking for
tell application "Safari"
get URL of every tab of every window
end tell
Now how I can call this from Python or JavaScript (I don't know if it's possible with JavaScript) ?
Someone have a great idea? Thank you!
There are two ways you can do this via python...
1.(My preference) Install appscript: pip install appscript
import appscript
urls = appscript.app('Safari').windows.tabs.URL()
2.Shell out to the commandline and call osascript:
from subprocess import Popen, PIPE
cmd = "/usr/bin/osascript -e 'tell application \"Safari\"' -e 'get URL of every tab of every window' -e 'end tell'"
pipe = Popen(cmd, shell=True, stdout=PIPE).stdout
urls = pipe.readlines()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With