Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to get the Url's of Safari for multiple browser instance??

Hi All,

am trying to get the URL's of the opened windows in more than one instance of Safari.

I have got the script to get the url's of single instance, Pls suggest the same for multiple instances of safari browser with different windows opened for each instance. current code am uisng:


tell application "System Events"
          set theURL to URL of current tab of window 1  
end tell

Mac OS X (10.7.4)

Posted on Nov 23, 2012 5:12 AM

Reply
6 replies

Nov 23, 2012 6:07 AM in response to madhusudhanjr

Off the top of my head, the only way I can think to do this is by some tricky fiddling with unix ids (which you can get in system events processes suite). But please, why are you making this huge headache for yourself? Unlike Linux, the Mac OS is designed around singleton instances of apps. You can convince it to open multiple instances, yes, but it's not something you should normally do without an awfully good reason, and when you do it with a big, complicated, greedy app like Safari you waste huge amounts of system resources and force yourself to jump through endless hoops in order to trick the system into doing something it's simply not intended to do.


Now, in my experience anyone who asks a question like this is going to pursue it come **** or high water. The fact that you've gotten to the point of asking for help implies that you've already expended a lot of time and effort on the problem, which implies further that you are fixated on accomplishing the goal. I will say, pro forma, that you ought to stop trying to make your Mac behave like a different OS and get used to the way the Mac OS works; that would be the sensible approach. If you choose not to take that advice - and frankly, it would surprise me if you did take it - then I would ask you to please have the grace not to waste everyone else's time by asking them to tilt at your windmill. Pounding your own head on such a pointless exercise can be written off as eccentric, possibly even romantic in a strange sort of way. Pounding other people's heads on it is just rude.

Nov 23, 2012 8:01 AM in response to madhusudhanjr

Not sure to perfectly understand what you are asking for. However maybe you might want to try the following script:


set theURLs to {}

tell application "System Events"

get id of processes whose name is "Safari"

repeat with thisID in result

tell windows of (process 1 whose id is thisID)

copy value of text field 1 of group 2 of tool bar 1 to the end of theURLs

end tell

end repeat

end tell

theURLs


Message was edited by: Pierre L.

Nov 26, 2012 1:07 AM in response to Pierre L.

Thanks Pierre, this helped me to get all the urls of Safari instances.

Is their any way to close the window of all instances by checking the window name contains "abc"??

currently I have got the solution to close the window based on name for single instance only..


tell application "Safari"

close (every window whose name contains "abc")

end tell

Nov 26, 2012 2:28 AM in response to madhusudhanjr

Try this:


set theURLs to {}

tell application "System Events"

get id of processes whose name is "Safari"

repeat with thisID in result

tell (process 1 whose id is thisID)

tell windows

copy value of text field 1 of group 2 of tool bar 1 to the end of theURLs

end tell

tell (windows whose name contains "abc")

clickbutton 1 -- close

end tell

end tell

end repeat

end tell

theURLs

Applescript to get the Url's of Safari for multiple browser instance??

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.