Skip to content

Instantly share code, notes, and snippets.

@grahama1970
Created January 22, 2025 21:12
Show Gist options
  • Save grahama1970/096d4d4654a06dde0fc9c8bf63512970 to your computer and use it in GitHub Desktop.
Save grahama1970/096d4d4654a06dde0fc9c8bf63512970 to your computer and use it in GitHub Desktop.
GlobiTab is a Raycast script that intelligently manages Chrome tabs using quicklinks (like 'gh' for GitHub). Unlike Raycast's built-in quicklinks that always create new tabs, GlobiTab first checks if the target URL already exists in any window. If found, it switches to that tab instead of creating a duplicate.
#!/usr/bin/osascript
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title GlobiTab
# @raycast.mode silent
# @raycast.icon 🔍
# @raycast.packageName GlobiTab
# @raycast.argument1 { "type": "text", "placeholder": "Tab Name/URL/Keyword", "optional": false }
# Optional parameters:
# @raycast.description Find or create Chrome tab by name, URL, or keyword. Doesn't create a new tab if the tab is already open.
# @raycast.author Graham Anderson
# @raycast.authorURL https://raycast.com/graham_anderson
on run argv
set searchQuery to item 1 of argv
set targetURL to getURLForQuery(searchQuery)
log "Search Query: " & searchQuery
log "Target URL: " & targetURL
tell application "Google Chrome"
activate
set windowTabList to URL of tabs of every window
set foundTab to false
set windowIndex to 1
repeat with thisWindowsTabs in windowTabList
set tabIndex to 1
repeat with tabURL in thisWindowsTabs
if my normalizeForSearch(tabURL as text) contains my normalizeForSearch(targetURL) then
set index of window windowIndex to 1
set active tab index of window 1 to tabIndex
set foundTab to true
log "Found and activated tab: " & tabURL
exit repeat
end if
set tabIndex to tabIndex + 1
end repeat
if foundTab then exit repeat
set windowIndex to windowIndex + 1
end repeat
if not foundTab then
log "Creating new tab with URL: " & targetURL
make new tab at end of tabs of window 1 with properties {URL:targetURL}
end if
end tell
return "Operation completed"
end run
on normalizeForSearch(inputText)
set lowercaseText to do shell script "echo " & quoted form of inputText & " | tr '[:upper:]' '[:lower:]'"
set cleanedText to do shell script "echo " & quoted form of lowercaseText & " | sed -E 's/https?:\\/\\///g; s/^www\\.//g; s/\\/.*$//g'"
set finalText to do shell script "echo " & quoted form of cleanedText & " | tr -d '[:space:]'"
log "Normalized text: " & finalText
return finalText
end normalizeForSearch
on getURLForQuery(query)
set normalizedQuery to my normalizeForSearch(query)
log "Normalized Query in getURLForQuery: " & normalizedQuery
set quicklinks to {¬
{keyword:"g", URL:"google.com"}, ¬
{keyword:"yt", URL:"youtube.com"}, ¬
{keyword:"gh", URL:"github.com"}, ¬
{keyword:"so", URL:"stackoverflow.com"}, ¬
{keyword:"a", URL:"amazon.com"}, ¬
{keyword:"ds", URL:"chat.deepseek.com"}, ¬
{keyword:"gpt", URL:"chatgpt.com"}, ¬
{keyword:"w", URL:"wikipedia.com"} ¬
}
repeat with quicklink in quicklinks
-- Use exact match for quicklinks
if normalizedQuery is equal to (keyword of quicklink) then
log "Matched quicklink: " & (keyword of quicklink)
return "https://" & (URL of quicklink)
end if
end repeat
-- Handle full domain inputs like apple.com
if query contains "." then
if query does not start with "http://" and query does not start with "https://" then
set query to "https://" & query
end if
log "Final URL (domain detected): " & query
return query
else
-- Treat as a search query if no dot is present
set query to "https://www.google.com/search?q=" & query
log "Final URL (search query): " & query
return query
end if
end getURLForQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment