Safari Close Tab Named Start or Close Leftmost Tab Needed

I created a macro to start Safari and Load a specific webpage.

I would like to closet the leftmost tab (which is also one tab to the left, which is also titled Start Page). I have accomplished this by a) using the window controls to put the window in a specific position and b) using the the mouse control to click at a particular point of the window. Not very elegant but it works!

I would like to find a more elegant and more reliable way of doing this; for example, closing the leftmost tab, closing the tab name Start Page (which I could do using AppleScript but I cannot get AppleScript to run within KM).

I searched both the forum and the internet in my search for a KM non-AppleScript solution but cannot and one.

Please show me the way.

Thanks.

You could do something like this:

Example Macro.kmmacros (1.9 KB)

Or, instead of closing that first tab, you could have KM open the webpage in it: actions:Browser Window Actions [Keyboard Maestro Wiki]

A huge thank you, again! It worked great!

It is interesting that KM is like any other piece of software, one needs to learn / know it capabilities and syntax in order to get things working!

The first bit I had done on my own earlier but could not find / see the ability to reference the menu!

You can mark this one done too!

Thank yoU!

1 Like

You don't have to select a tab in order to close it.

tell application "Safari"
   tell front window
      close (tabs whose name starts with "Start Page")
   end tell
end tell

You can also do this by index.

tell application "Safari"
   tell front window
      set currentTabIndex to index of current tab
      set leftTabIndex to currentTabIndex - 1
      try
         close tab leftTabIndex
      end try
   end tell
end tell
1 Like

All good! The funny thing is that I wrote that code myself in AS but because I could not get AS to work until you pointed out that I did not have all the permissions I was looking for others way to do it.

I will add that I appreciate your AS as my AS skillset is also at the early stages.

I would like to see AS stick around due to its power but I heard it is may be deprecated! I hope not!

There have been rumors for 20 years...

Considering the vast automation code base of vanilla AppleScript, AppleScriptObjC, JXA, and the up and coming Shortcuts which supports AppleScript I think deprecation has been deprecated.

Automator is going under sometime soon though.

I hope you are correct!