Getting past Paywalls on a Mac with Safari

An AppleScript to Turn Javascript ON/OFF in Safari

I started to write this article a while back and had left in my drafts bin. I recently started using this AppleScript again, so I thought I update and post this blog entry. This technique, although not infallible, works on a surprising number of websites.

The Problem: A number of news websites throw up a paywall, using a Javascript blocker, sometimes immediately and sometimes when you have viewed more a certain number of articles in a given period.

The ‘Right’ Solution: Subscribe to the publication and support the whole journalistic enterprise. See: The Truth is Paywalled But Lies are Free. When this doesn’t work for you…


A Simple Solution: Turn off Javascript in Safari (Safari Menu, Preferences, Security Panel, toggle ‘Enable Javascript’) and then the reload (Command R) the web page. Remember to toggle Javascript back on, because so much of the display of the modern web relies on it, that it really isn’t very functional without Javascript turned on. This works for casual use, but if you find yourself seeking to avoid paywalls often, you may want to go the next step.

Note: this technique will work on an iPhone as well. Go to Settings: Safari: Advanced (the bottom of the list): Javascript toggle. It isn't as convenient to get to to toggle on and off, but it seems to work.

The High Volume Solution: Script the toggling of Javascript and attach it to a hot key or use it with Spotlight.

I found an AppleScript to perform the toggling action, but it was a little bit dated. It didn’t seem to work properly on my Mac, partly because Apple had moved the GUI scripting function into the Security & Privacy System Preferences panel. I have updated the AppleScript and have added a Page Reload to speed up viewing in Safari.

Page Blocker appears with Javascript turned ON


Javascript turned OFF – No Page Blocker

nyt-withoutpaywallApplescript for Safari to Toggle Javascript On/Off

Apologies for the somewhat messy formatting below. It will clean up when you paste it into the AppleScript Editor and click the Compile button.

--updated for Mavericks 2014-03-09 
tell application "Safari" to activate

tell application "System Events"
if (system attribute "sysv") < 4144 or UI elements enabled then
tell application process "Safari"
-- open Preferences window
click menu item "Preferences…" of menu ¬
"Safari" of menu bar item "Safari" of menu bar 1
-- window title varies according to type of Prefs initially selected, ¬
--so save to a variable
get value of static text 1 of window 1
copy the result as string to varWindowName
-- switch to Security Prefs
click button "Security" of toolbar 1 of window varWindowName
-- toggles JavaScript checkbox
click checkbox "Enable JavaScript" of group 1 ¬
of group 1 of window "Security"
-- get new state for confirmation dialog
get value of checkbox "Enable Javascript" of ¬
group 1 of group 1 of window "Security"
copy the result as number to varResult
--toggle the Javascript setting ON or OFF — if ON, then set to OFF etc.
if varResult = 0 then
set varResult to "OFF"
set varResult to "ON"
end if

-- close Preferences window
click button 1 of window "Security"
--reload the page, with/without Javascript running.
click menu item "Reload Page" of menu ¬
"View" of menu bar item "View" of menu bar 1
--display confirmation dialog - this is just annoying, but you can turn 
--it on when debugging the script.
--display dialog ("\"Toggle JavaScript\" script confirmation:" 
--& return & return & "JavaScript is now " & varResult & ".") 
--buttons {"OK"}
--default button "OK" giving up after 7 with icon 1
end tell

--check to see if the AppleScript Editor has permission to run in 
--the Security and Privacy System Preferences panel on Mavericks.
tell application "System Preferences"
set current pane to pane ""

-- NOTE: The following section has a hard-coded return between
-- 'Universal Access' and 'preference pane'. Replace it with a
-- single space.
display dialog ¬
"Security & Privacy Setting Not Enabled." & return & return & ¬
"Check \"Allow apps to control your computer, specifically the ¬
'AppleScript'\" in the Security & Privacy preference pane ¬
(authentication is required), then run this script again." with icon stop ¬
buttons {"OK"} default button "OK"
end tell

end if

end tell

 AppleScript Editor

Copy the script above and paste it into the AppleScript Editor. Save the file as an Application with the name ‘Toggle Javascript in’ in your Applications folder for future reference.

System Preferences: Security & Privacy Panel

To allow this script to run properly, it must have permission in the System Preferences: Security & Privacy Panel: Privacy: Accessibility.

Security Settings to Allow the AppleScript to Run

Apple has increased the security in OS X Mavericks, instead of a global UI Scripting switch, there are now specific permissions for individual apps. You will need to turn on the permission to allow the AppleScript app to control your computer.
  1. Unlock the Privacy setting under the Accessibility area by clicking the small lock icon in the lower left of the screen.
  2. Click on the Accessibility panel
  3. Allow the apps below to control your computer — check the little box to the left of the AppleScript application to turn on permission for the newly created AppleScript ‘Toggle Javascript in’

Spotlight used to run the AppleScript to toggle Javascript on or off

toggle in Spotlight

Typing Command-Spacebar brings up the Spotlight panel to search for files or applications. Typing in ‘Toggle’ brings up the script, and then hitting ENTER causes it to run. There are other methods to do this, using macro apps like Alfred or Keyboard Maestro, but Spotlight serves my purposes and is built-in and free to use.

3 Responses to “Getting past Paywalls on a Mac with Safari”

  1. Hello,

    Each time I run the app, I receive an error message “Toggle Javascript On/Off is not authorized to a help access (-1719)” (translated from French). With two buttons, OK and MODIFY. The MODIFY button open the editor with the app in it. OK just close the message.

    Thank you

%d bloggers like this: