AI and scripting - Personal Experience writing an AppleScript using AI

I like the idea of tab groups in Safari to house tabs for different aspects of my work and personal life. For example, I have a set of travel-related websites in a Travel tab. I have another group of tabs open in a Macsparky tab group related to MPU, MacSparky Labs and Automators. And so on and so forth.

These groups sound good, but I frequently find myself navigating away from the websites I pinned in the group in the first place as I dive down rabbit holes in each. And I also find myself opening or having other apps opening) tabs in this group, simply because that particular tab group is in the foreground on Safari when I click on a link from, say, Mail.

I’ve been looking for a way to restore the “baseline” tabs when I want to start fresh in that group. Right now, there does not appear to be a way to do this via Shortcuts (really?!?) on the Mac (nor, do I believe the more extensive tab actions in the iOS/iPadOS version of shortcuts will do what I am looking to do but I might be wrong as I haven’t tried that).

It occurred to me that an AppleScript might do the job (hint: it will!). I then also thought: “I don’t know AppleScript all that well” and I had read about how the ChatGPT AI application could code, so I figured I’d give it a try.

And it worked! I simply told it that I wanted to close all the tabs in Safari and re-open my “baseline” tabs. I hit enter and 5 seconds later it spat back out the following AppleScript:

====================================
tell application “Safari”
activate
close every tab of the front window
open location “www.website1.com
open location “www.website2.com
open location “www.website3.com
open location “www.website4.com
open location “www.website5.com
end tell

====================================

Now, that’s not a very complicated script, but it was exactly what I needed. I replaced the generic website URLs in the script with the ones I want to open and then linked it to a Keyboard Masestro conflict pallette and I’m in business.

I’m sure I could have figured out how to script this “by hand” via Google, but it would have taken much longer than 5 seconds.

I am deeply skeptical of this technology, both for ethical reasons (cheating in school, etc…) and the potential for abuse and possible weaponization (Terminator, anyone?). But for very basic tasks like this, it could be very very useful. I’m just not sure we can separate the good from the bad.

3 Likes