6 Replies Latest reply: Nov 26, 2012 4:06 AM by madhusudhanjr
madhusudhanjr Level 1 Level 1 (0 points)

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)
  • twtwtw Level 5 Level 5 (4,900 points)

    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.

  • Pierre L. Level 5 Level 5 (4,115 points)

    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.

  • madhusudhanjr Level 1 Level 1 (0 points)

    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

  • Pierre L. Level 5 Level 5 (4,115 points)

    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")

                    click button 1 -- close

                end tell

            end tell

        end repeat

    end tell

    theURLs

  • madhusudhanjr Level 1 Level 1 (0 points)

    thanks a lot.. its working..

  • madhusudhanjr Level 1 Level 1 (0 points)

    thanks for your suggestion, actually this is one of my project requirement whr am stuck so finding some ways for the same.