Automating Arc Browser with AppleScript
Automating Arc Browser with AppleScript
A while back I switched to using Arc as my daily browser. It boasts neat features and a delightful design. On top of that, it also integrates nicely with AppleScript.
Focus a specific Arc Space from AppleScript
The following AppleScript focuses the Space “Personal”.
tell application "Arc"
tell front window
tell space "Personal" to focus
end tell
activate
end tell
Open an Arc Space through Apple Shortcuts
The code above can be executed in Shortcuts using the Run AppleScript action. I organized the logic into a reusable shortcut for conveniently setting an Arc Space from other shortcuts.
↪ Open Arc Space shortcut | iCloud
Reusable shortcut “Open Arc Space”
Running the “Open Arc Space” shortcut from another shortcut.
Focus a tab in a specific Space
Let’s take it a step further! This script switches to a Space in Arc and focuses on a tab using the specified index.
This snippet focuses the first tab of the space Personal:
tell application "Arc"
tell front window
tell space "Personal"
tell tab 1 to select
end tell
end tell
activate
end tell
Arc’s count includes Pinned Tabs. So tab 1
is always the first pinned tab.
Focus pinned tab on key combination
I created a space with localhost:3000
pinned as the first tab. With Hammerspoon, I can assign a keystroke to jump to that tab. Now, pressing Hyper + a
focuses localhost:3000
for development, regardless of the active window.
-- init.lua
-- focus localhost
Hyper:bind({}, "a", nil, function()
hs.osascript.applescript([[
tell application "Arc"
tell front window
tell space "Develop"
tell tab 1 to select
end tell
end tell
activate
end tell
]])
end)
Open multiple links in Arc
There is a bit of “gotcha” when automating Arc. Which behaviour would you expect out when running the code blow?
open location "https://google.com"
open location "https://duckduckgo.com"
My guess is, you’d expect two tabs to open. One containing Google, one containing DuckDuckGo. Instead, Arc opens the first url in a “Little Arc” window and then replaces it with the second url in the same window. For a brief moment Google is opened, then replaced by DuckDuckGo.
Running a script that opens Google, waits for three seconds and then opens DuckDuckGo.
Luckily, AppleScript can help us out here. By specifying a Space for tabs to open, Arc opens the urls in a “full” window.
tell application "Arc"
tell front window
tell space "Personal"
make new tab with properties {URL:"https://google.com/"}
make new tab with properties {URL:"https://www.duckduckgo.com/"}
end tell
end tell
activate
end tell
Digging into the source code of Arc’s Raycast extension
Arc has an official extension for Raycast which uses these AppleScript scripts under the hood. The source code is openly available. It contains the functions above and a few more. Happy scripting!