Applescript to set non focus tab in safari
set targetUrl to "https://www.apple.com"
use currentApp : application "Safari"
set _T to a reference to (every tab of every window of currentApp whose ¬
    URL contains targetUrl)

if (count _T) &gt; 0 then return viewTab(_T)
end

to viewTab(aURL)
    set [aURL] to aURL
    set W to the first window of currentApp whose tabs contains aURL

    set current tab of W to aURL
    activate currentApp
    set the index of W to 1
end viewTab


Source