safari-automation

safari-automation is a cursor rule for coding agents from steipete/agent-rules. It costs 0 tokens per session (1,424 once invoked), scanned A, original, MIT.

A guide to using AppleScript to control Safari windows and tabs for web automation and testing. AppleScript is Apple's scripting language for automating applications.

In plain words
What is it for?
Use it to open or reuse Safari tabs, navigate to URLs, refresh pages, and build repeatable web UI tests.
Why use it?
It helps avoid unreliable browser automation caused by choosing the wrong window or tab.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/steipete/agent-rules/safari-automation
Clone the repo
git clone --depth 1 https://github.com/steipete/agent-rules

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for safari-automation

README.md
[![agentmods](https://agentmods.dev/badge/rules/steipete/agent-rules/safari-automation.svg)](https://agentmods.dev/rules/steipete/agent-rules/safari-automation)
Your own site
<a href="https://agentmods.dev/rules/steipete/agent-rules/safari-automation"><img src="https://agentmods.dev/badge/rules/steipete/agent-rules/safari-automation.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,424 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01424
Opus 5 $0.00000 $0.00712
Sonnet 5 $0.00000 $0.00285
Haiku 4.5 $0.00000 $0.00142

Measured 5d ago against content hash bdf28d6069de, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

safari-automation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

project-rules/safari-automation.mdc · 203 lines

How it starts

The opening of the file, as written. The whole thing — 203 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Safari Automation Guide

This guide captures hard-won lessons from automating Safari interactions, particularly for web UI automation and testing.

Key Concepts

Managing Safari Windows and Tabs

Objective: Reliably direct Safari to specific URLs in a predictable way, preferably using a single, consistent browser window and tab.

Recommended Approach:

tell application "Safari"
  activate
  delay 0.2 -- Allow Safari to become the frontmost application
  if (count of windows) is 0 then
    -- No Safari windows are open, so create a new one.
    make new document with properties {URL:"http://example.com"}
  else
    -- Safari has windows open; use the frontmost one.
    tell front window
      set targetTab to missing value
      try
        -- Check if a tab for the target URL is already open
        set targetTab to (first tab whose URL starts with "http://example.com")
      end try
      
      if targetTab is not missing value then
        -- Reuse existing tab: refresh and make active
        set URL of targetTab to "http://example.com"
        set current tab to targetTab
      else
        -- No specific tab found: use current active tab
        set URL of current tab to "http://example.com"
      end if
    end tell
  end if
  delay 1 -- Pause to allow the page to begin loading
end tell

JavaScript Execution in AppleScript

String Escaping Strategies:

  1. Using Escaped Quotes:

    do JavaScript "document.querySelector('[data-testid=\\'my-button\\']').click();"
    
  2. Using character id 39 for Complex Strings:

    set sQuote to character id 39
    set jsSelector to "[data-testid=" & sQuote & "my-button" & sQuote & "]"
    set jsCommand to "document.querySelector(" & sQuote & jsSelector & sQuote & ").click();"
    do JavaScript jsCommand in front document
    
  3. XPath for Robust Element Selection:

    -- Find button containing specific text
    set jsCommand to "document.evaluate(\"//button[.//text()='Connect']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();"
    do JavaScript jsCommand in front document
    

Read the full file on GitHub · 203 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 203 lines · 0 tokens per session scan A bdf28d6069de

Subscribe to this mod's changes

safari-automation is a cursor rule published in the GitHub repository steipete/agent-rules (5,694 stars, last pushed 4mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,424 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.