Open the user's browser or go to the appropriate tab if the website is already open.

In my Objective-C application, I use this code to open a website in the user's browser:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"https://blah.com/"]]; 

It works great. However, there is one small problem; if the user has already opened "blah.com" in his web browser, calling it, he creates a new tab.

It would be better if the user simply switched to the existing tab in these cases.

Is there any way to do this? Please note that I would also like to switch to an existing tab if the tab is on the subpage "blah.com", for example "blah.com/some/page.html".

+6
source share
1 answer

You cannot do this with -[NSWorkspace openURL:] . If you know that the user is using Chrome or Safari, you can do this by running AppleScript.

0
source

Source: https://habr.com/ru/post/901871/


All Articles