Direct answer
Yes, but first you have to turn on a browser switch that is off by default, allowing JavaScript from Apple Events, and then pass the system's Automation prompt. You do both steps yourself in the remote desktop.
Basis
- Safari's scripting dictionary has a
do JavaScriptcommand that runs a piece of script in a given tab and returns the result. By default it is refused; you need to show the developer features first and then tick “Allow JavaScript from Apple Events”. - The matching command in Chrome is
execute javascript, and the allow option of the same name is in the Developer submenu of the View menu. Menu locations in both browsers shift between versions, so go by what you see on your machine. - On top of the browser's own switch, the system shows an Automation prompt the first time a script controls the browser, and you need to click Allow.
- This approach operates on the browser window you are actually using, with its existing logins and extensions; WebDriver-style test tools start a separate controlled session instead. The two suit different jobs.
Boundaries: when the answer is different
Once this switch is on, any script that has Automation permission can read page content, including data on sites you are signed in to. Create a separate browser profile for automation and do not mix it with a profile that holds important accounts. Many websites restrict automated access in their terms of service and have their own detection; using scripts to circumvent a third-party platform's security mechanisms is a prohibited use and can lead to suspension of the machine and termination of service. Selectors stop working when a page is redesigned, which is normal for scripts like this, and we do not guarantee that any particular website can be automated.
How to do it
- Turn on the web developer features in Safari's settings, then find and tick the option that allows JavaScript from Apple Events.
- In Script Editor, write a one-line script that makes the current tab return
document.title. - Run it, and in the system prompt allow Script Editor to control Safari.
- Once you get the title back, swap in your real logic, and add a timeout and failure logging to each step.
- Turn the browser switch off again when you no longer need it.
Related questions
- iMessage, AppleScript and Shortcuts on a rented Mac mini: it runs, but Apple decides about your account
- Can an AI agent control the screen and browser on a rented Mac?
- How do I fix AppleScript error -1743, “Not authorized to send Apple events”?
- How do I tell whether a macOS app can be controlled by a script?
- Automation vs Accessibility permission on macOS: which does my script need?
Use case
This question belongs to the use case: iMessage, AppleScript and Shortcuts on a rented Mac mini: it runs, but Apple decides about your account
Other questions in the same use case:
- AppleScript vs Shortcuts vs JXA: which to use for automation on a remote Mac?
- launchd or cron: which should I use for scheduled jobs on a remote Mac?
- Will using iMessage on a rented Mac mini get my Apple account restricted?
- Can I use a rented Mac mini to send bulk iMessage marketing?
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support