Skip to content

Instantly share code, notes, and snippets.

@kush-daga
Created March 8, 2023 15:00
Show Gist options
  • Save kush-daga/db18cd82b161310cbe06be2836bb644d to your computer and use it in GitHub Desktop.
Save kush-daga/db18cd82b161310cbe06be2836bb644d to your computer and use it in GitHub Desktop.
ScriptKid script to focus on Slack tab in Arc
import "@johnlindquist/kit"
// Menu: Open Slack on Arc
// Description: Open Slack tab in arc
// Author: Kush Daga
// Twitter: @KushDaga
const getTabs = async () => {
const response = await applescript(`
on escape_value(this_text)
set AppleScript's text item delimiters to the "\\""
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the "\\\\\\""
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
set _output to ""
tell application "Arc"
set _window_index to 1
set _tab_index to 1
repeat with _tab in tabs of first window
set _title to my escape_value(get title of _tab)
set _url to get URL of _tab
set _location to get location of _tab
set _output to (_output & "{ \\"title\\": \\"" & _title & "\\", \\"url\\": \\"" & _url & "\\", \\"windowId\\": " & _window_index & ", \\"tabId\\": " & _tab_index & " , \\"location\\": \\"" & _location & "\\" }")
if _tab_index < (count tabs of first window) then
set _output to (_output & ",\\n")
else
set _output to (_output & "\\n")
end if
set _tab_index to _tab_index + 1
end repeat
end tell
return "[\\n" & _output & "\\n]"
`);
return response ? (JSON.parse(response)) : undefined;
}
const focusTab = async (tab) => {
await applescript(`
tell application "Arc"
tell window (${tab.windowId} as number)
tell tab (${tab.tabId} as number) to select
end tell
activate
end tell
`)
}
const tabs = await getTabs()
const tab = tabs.find(t => t.title.toLowerCase().includes("slack"));
await focusTab(tab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment