Safari and AppleScript

I’ve used a Mac since the early 1990s and have never learned AppleScript. No time like the present!

I was trying to do something that seems so simple, but the answer was eluding me. My goal was to write a script accessible with a FastScripts keyboard shortcut that would:

  1. open a new Safari browser window if one wasn’t open, or
  2. simply activate Safari if a window was already open.

Hypert solved my problem with a hint from 2004.

Here is the elusive script.

The script not only does what I hoped, but also creates a new window if the Downloads window or minimized Safari window already exists. I’m still working through the script to learn how it works, and my aging brain is slowly getting it.

So, thanks hypert!

Advertisements