Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just so we have it, here is a script to disable Javascript in Safari, showing just the business logic for brevity:

  tell application "System Events" to tell process "Safari" to tell menu item "Disable JavaScript" of menu 1 of menu bar item "Develop" of menu bar 1
    if (value of attribute "AXMenuItemMarkChar" as string) is "missing value" then click
  end tell
I save it as an application called Disable Javascript under User Scripts in Script menu and enable assistive access for it.

You can attach a keyboard shortcut to any menu, for example System Preferences->Keyboard->App Shortcuts->Safari->Disable Javascript with command-J. Unfortunately that just toggles Javascript, with no visible indication of whether it's on.

You used to be able to assign a keyboard shortcut to launch applications and scripts, but Apple borked that long ago:

https://apple.stackexchange.com/questions/175215/how-do-i-as...

So instead, I created Automator->Service->Run Shell Script with:

  osascript -e 'tell application "Disable Javascript" to activate'
Then saved it as service "Disable Javascript". Then System Preferences->Keyboard->Services->General->Disable Javascript with shift-command-J.

Now I just periodically press shift-command-J while browsing. If a tab won't render, I press command-J, command-R to reload, then command-J again so the tab doesn't use resources.

I used to have a script to launch Safari with Javascript disabled, but Apple changed how it worked so that the flag is stored in their SQLite preferences somewhere, and I just never found time to re-implement it. If anyone knows a way, I'm all ears!

--

Edit: HN stripped the checkmark character (https://www.compart.com/en/unicode/U+2713) when I pasted, even though I made it a code block by prefixing each line with 2 spaces. So I changed the line to:

  if (value of attribute "AXMenuItemMarkChar" as string) is "missing value" then click
Sorry if that prevented the scripts from working!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: