Open automator and create an application script called safe-safari-session-to-clipboard-json.app
.
-
Add a JavaScript step with the following content
function run(input, parameters) { var _urlList = []; var _safari = Application('Safari'); _safari.includeStandardAdditions = true; _safari.activate(); _safari.windows().forEach(function (_window) { _window.tabs().forEach(function (_tab) { _urlList.push({"name": _tab.name(), "url": _tab.url()}); }); }); // Pretty print the stringified JSON object before returning it. For a condensed JSON string simply remove the last // two parameters from the method call below. I.e. return JSON.stringify(urlList); return JSON.stringify(_urlList, null, 2); }
-
Add a copy to clipboard step
To test this application within Automator, add the “Get Specified Finder Items” action to the beginning of your workflow without forgetting to remove or disable the action before running the workflow outside of Automator.
Example output:
[
{
"name": "Teach, Learn, and Make with Raspberry Pi – Raspberry Pi",
"url": "https://www.raspberrypi.org/"
},
{
"name": "Home - BBC News",
"url": "https://www.bbc.co.uk/news"
}
]
Open automator and create an application script called safe-safari-session-to-clipboard-markdown.app
.
-
Add a JavaScript step with the following content
function run(input, parameters) { var _urlList = []; var _safari = Application('Safari'); _safari.includeStandardAdditions = true; _safari.activate(); _safari.windows().forEach(function (_window) { _window.tabs().forEach(function (_tab) { _urlList.push("- [" + _tab.name() + "](" + _tab.url() + ")"); }); }); return _urlList.join("\n"); }
-
Add a copy to clipboard step
To test this application within Automator, add the “Get Specified Finder Items” action to the beginning of your workflow without forgetting to remove or disable the action before running the workflow outside of Automator.
Example output:
- [Teach, Learn, and Make with Raspberry Pi – Raspberry Pi](https://www.raspberrypi.org/)
- [Home - BBC News](https://www.bbc.co.uk/news)