It works almost perfectly for my need! Thanks Chris!
Only thing is would like it to make a new tab instead of a new window in the else action.
This is one of my first scripts I have used, and I tried to rewrite it but it didn´t seem to work.
tell application "Google Chrome"
set newWin to make new window <— Changing new window to new tab didn´t work
tell newWin to set URL of active tab to "https://fronter.com/oa/main.phtml"
end tell
You can compare the original with this new script and see the change was pretty minor.
TextWrangler (freeware) can do direct file-compares to make that task a bit easier.
Don’t let that bother you too much – programming is not always very intuitive – particularly if you haven’t studied the language.
-Chris
-----------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
# dCre: 2015/05/14 12:30
# dMod: 2016/12/08 11:40
# Appl: Google Chrome, System Events
# Task: Bring Chrome Tab with Keyboard Maestro Forum to front if it exists - otherwise open KMF in new tab.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Google_Chrome, @System_Events, @Open, @Keyboard_Maestro, @KM, @Forum
# Test: macOS 10.11.6 with Google Chrome 54.0.2840.59
-----------------------------------------------------------------
set _win to false
tell application "Google Chrome"
set {idList, urlList} to {id, URL} of every tab of every window
end tell
set AppleScript's text item delimiters to linefeed
if (urlList as text) contains "https://forum.keyboardmaestro.com" = true then
set theWin to 1
repeat with i in urlList
set theTab to 1
repeat with n in i
if n starts with "https://forum.keyboardmaestro.com" then
set {_win, _tab} to {theWin, theTab}
end if
set theTab to theTab + 1
end repeat
set theWin to theWin + 1
end repeat
end if
if _win ≠ false then
tell application "System Events"
if quit delay ≠ 0 then set quit delay to 0
tell process "Google Chrome"
perform action "AXRaise" of window _win
end tell
end tell
tell application "Google Chrome"
tell front window to set active tab index to _tab
end tell
else
tell application "Google Chrome"
tell front window
make new tab at end of tabs with properties {URL:"https://forum.keyboardmaestro.com"}
end tell
end tell
end if
-----------------------------------------------------------------