Creating a Mac Automator workflow to show the Safari start page when Command-W is pressed, but only when there is only one open regular tab, involves a combination of Automator and AppleScript. Here's a step-by-step guide on how to set it up:
Open Automator:Launch Automator from your Applications folder or by searching for it in Spotlight.
Launch Automator from your Applications folder or by searching for it in Spotlight.
Create a New Service:In Automator, select "File" from the menu bar, then choose "New" and select "Service."
In Automator, select "File" from the menu bar, then choose "New" and select "Service."
Configure the Workflow:In the top-right corner of the Automator window, make sure that "Service receives" is set to "no input" in "any application."In the Actions Library (left pane), search for "Run AppleScript" and drag it to the workflow area on the right.
In the top-right corner of the Automator window, make sure that "Service receives" is set to "no input" in "any application."
In the Actions Library (left pane), search for "Run AppleScript" and drag it to the workflow area on the right.
Write the AppleScript:Replace the default AppleScript template in the "Run AppleScript" action with the following script:
Replace the default AppleScript template in the "Run AppleScript" action with the following script:
Open Automator:
Launch Automator from your Applications folder or by searching for it in Spotlight.
Launch Automator from your Applications folder or by searching for it in Spotlight.
Create a New Service:
In Automator, select "File" from the menu bar, then choose "New" and select "Service."
In Automator, select "File" from the menu bar, then choose "New" and select "Service."
Configure the Workflow:
In the top-right corner of the Automator window, make sure that "Service receives" is set to "no input" in "any application."
In the Actions Library (left pane), search for "Run AppleScript" and drag it to the workflow area on the right.
In the top-right corner of the Automator window, make sure that "Service receives" is set to "no input" in "any application."
In the Actions Library (left pane), search for "Run AppleScript" and drag it to the workflow area on the right.
Write the AppleScript:
Replace the default AppleScript template in the "Run AppleScript" action with the following script:
Replace the default AppleScript template in the "Run AppleScript" action with the following script:
────────────────────────────────────────────────────────────────────
applescriptCopy codeon run {input, parameters}
tell application "Safari"
set tabCount to count of tabs of window 1
if tabCount is 1 then
set currentTab to (current tab of window 1)
if class of currentTab is tab then
set URL of currentTab to "about:blank"
end if
end if
end tell
return input
end run
This AppleScript checks if there is only one regular tab open in Safari (not including pinned tabs), and if so, it sets the current tab's URL to "about:blank," effectively showing the Safari start page.
Save the Workflow:Go to "File" and choose "Save..."Give your service a name, such as "Close Safari Tab to Show Start Page."Click "Save."
Go to "File" and choose "Save..."
Give your service a name, such as "Close Safari Tab to Show Start Page."
Click "Save."
Configure Keyboard Shortcut:Open "System Preferences" on your Mac.Navigate to "Keyboard" > "Shortcuts."Select "Services" from the left sidebar.Scroll down to the "General" section and find your service (it should be under "Text").Click on the service name to the right, and then click the "Add Shortcut" button.Enter the desired keyboard shortcut, such as Command-W.Ensure that the shortcut doesn't conflict with any existing shortcuts.
Open "System Preferences" on your .
Navigate to "Keyboard" > "Shortcuts."
Select "Services" from the left sidebar.
Scroll down to the "General" section and find your service (it should be under "Text").
Click on the service name to the right, and then click the "Add Shortcut" button.
Enter the desired keyboard shortcut, such as Command-W.
Ensure that the shortcut doesn't conflict with any existing shortcuts.
Save the Workflow:
Go to "File" and choose "Save..."
Give your service a name, such as "Close Safari Tab to Show Start Page."
Click "Save."
Go to "File" and choose "Save..."
Give your service a name, such as "Close Safari Tab to Show Start Page."
Click "Save."
Configure Keyboard Shortcut:
Open "System Preferences" on your .
Navigate to "Keyboard" > "Shortcuts."
Select "Services" from the left sidebar.
Scroll down to the "General" section and find your service (it should be under "Text").
Click on the service name to the right, and then click the "Add Shortcut" button.
Enter the desired keyboard shortcut, such as Command-W.
Ensure that the shortcut doesn't conflict with any existing shortcuts.
Open "System Preferences" on your .
Navigate to "Keyboard" > "Shortcuts."
Select "Services" from the left sidebar.
Scroll down to the "General" section and find your service (it should be under "Text").
Click on the service name to the right, and then click the "Add Shortcut" button.
Enter the desired keyboard shortcut, such as Command-W.
Ensure that the shortcut doesn't conflict with any existing shortcuts.
Now, when you press Command-W in Safari with only one regular tab open, it will close the tab and show the Safari start page. Please note that this workflow won't work if there are multiple tabs open, including pinned tabs, as it specifically checks for a single regular tab.