AppleScript: Back Page Function in Browsers

This week at work, I realized how pre-2010 my Mac’s Mighty Mouse was. There is a set of buttons on the side of the mouse, but it doesn’t even serve any functions! Namely, it doesn’t allow me to go back a back (aka a “back page” operation, if that’s what it’s called) on the browser. At home, I use the Logitech Performance MX mouse, and on Windows at least, the side buttons are preconfigured to do exactly that, and more (go forward a page), when pressed.

Being a OS X newbie, I decided to create a simple AppleScript macro to perform just this function.  It probably isn’t the best solution by far, but at least it works! Good enough.

I looked around the Internet, and patched together this script for my problem.

In AppleScript Editor:

tell application "Google Chrome" to activate
tell application "System Events"
    key code 51
end tell


Key code 51 represents the delete button in OS X. This script presses the delete button once in Chrome (or “Firefox” for Mozilla Firefox, “Safari” for Safari), which performs a “backpage” operation on the browser.

AppleScript back page previous

To bind it with the side buttons of my Mighty Mouse, I saved it as an application instead of a script file.

AppleScript back page macro as application

Then, in the control panel, I bound it to button 4 (the side buttons) of the mouse.

os x control panel applescript


And yes! A cumbersome (and probably not-so-smart) way to use the side buttons of your Apple mouse.

Kevin Lin

I am a Software Engineer at Qualtrics in Seattle! To learn a little more about me, please visit the "Meet Kevin" widget on the top right on the screen!
Posted in Code.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.