Hi
I have tried to mod @ccstone’s script
I wanted to select a tab & activate if URL search returned more then 1 tab
I tried but cud not Display Title of tab in Prompt to select tab
I think the Activate tab Handler cud be lot better !
Third Try-> works, is it possible to hide “winID” & “tabID”, show titleID in prompt, but return winID & tabID of selection ?
tell application "Google Chrome"
set restoreURL to URL of active tab of front window as text
#set targetURL to "https://www.extendoffice.com/"
set targetURL to "nysora.com"
tell application "Google Chrome"
tell windows
set tabList to tabs where its URL contains targetURL
-- -->>> set TitleList to title of tabs where its URL starts with targetURL
end tell
end tell
try
tabList / 0
on error e
set oldDelims to (get AppleScript's text item delimiters)
set AppleScript's text item delimiters to {"Can’t make {", "} into type real.", "{", "}", ", ", "«class asDB» id (application \"Google Chrome\") of "}
set tabList to text items of e
repeat with theTab in tabList
if contents of theTab = "" then set contents of theTab to 0
end repeat
set tabList to text of tabList
set AppleScript's text item delimiters to oldDelims
if length of tabList = 0 then
display dialog "No match was found!" buttons {"OK"} default button 1
--Or Create new tab with url
# tell application "Google Chrome" to make new tab at window 1 with properties {URL:targetURL}
else if length of tabList = 1 then
set theTab to item 1 of tabList
ActivateTab(theTab) of me
else
set tab_MatchList to {}
set oldDelims to (get AppleScript's text item delimiters)
set AppleScript's text item delimiters to {"id ", " of"}
repeat with theTab in tabList
set {tabID, winID} to {text item 2, text item 4} of theTab
set titleID to GetTitle(tabID, winID) of me
set end of tab_MatchList to winID & "- " & tabID & "- " & titleID
set tabID to tabID as integer
end repeat
set AppleScript's text item delimiters to oldDelims
-- Req help to get Title of Tab Here
set which_Tab to choose from list of tab_MatchList with prompt "The following Tabs matched, please select one:"
if which_Tab is not equal to false then
set oldDelims to (get AppleScript's text item delimiters)
set AppleScript's text item delimiters to "-"
set tmp to text items of (which_Tab as string)
set tabID to (item 2 of tmp) as integer
set winID to (item 1 of tmp) as integer
set AppleScript's text item delimiters to oldDelims
findTabID(tabID, winID) of me
raiseWindowOne() of me -- brings tabs to front
end if
end if
end try
end tell
--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on raiseWindowOne()
tell application "System Events"
tell application process "Google Chrome"
tell window 1
perform action "AXRaise"
end tell
end tell
end tell
end raiseWindowOne
------------------------------------------------------------------------------
on GetTitle(tabID, winID)
tell application "Google Chrome" to set titleTab to (get title of tab id tabID of window id winID)
return titleTab
end GetTitle
-------------------------------------
on ActivateTab(theTab)
-- Needs Handlers --> findTabID & raiseWindowOne
set oldDelims to (get AppleScript's text item delimiters)
set AppleScript's text item delimiters to {"id ", " of"}
set {tabID, winID} to {text item 2, text item 4} of theTab
set tabID to tabID as integer
set AppleScript's text item delimiters to oldDelims
tell application "Google Chrome" to set tabIDList to id of tabs of window id winID
findTabID(tabID, winID) of me -- Finds tabID & activates it
raiseWindowOne() of me -- brings tabs to front
end ActivateTab
----------------------------------------------------------------------------------
on findTabID(tabID, winID)
tell application "Google Chrome" to set tabIDList to id of tabs of window id winID
repeat with i from 1 to length of tabIDList
if (item i of tabIDList) = tabID then
set tabIndex to i
exit repeat
end if
end repeat
tell application "Google Chrome"
tell window id winID
set index to 1
set active tab index to tabIndex
end tell
end tell
end findTabID