If you open Alfred and press cmd (⌘) + , you can go to “Workflows” and add a new workflow using the Plus button.
Add a “Run Applescript” action by right-clicking in empty space. Paste the code between the two existing lines. (Full code at the end of my post here)
Choose an input, like a keyword, that you want to use to trigger the script. In this case no argument would be required, but in some cases you do want to give input. (For example: when I use it with my “Save Chrome tabs to file” I have an optional argument for the filename.)
This is one reason why I would recommend this method over @lbutlr suggestion to save it as an application, although he is correct and that would be a quick way to do it.
Now just start Alfred, type your keyword, and watch the magic.
I’ve put the complete action on one of my websites, so you can just import that and use it with the keyword “safpaper”. But I would highly recommend actually following the steps yourself and creating it, because you’ll learn some new things!
Anyway, download link if you want it: https://strategischlui.nl/wp-content/uploads/Save-Safari-Tabs.alfredworkflow
And the full script to copy/paste for the more manual route (it’s just the previous script between the on alfred_script lines)
-- might be just your email address
set instapaper_username to ""
-- only if you have one, not all Instapaper accounts have passwords
set instapaper_password to ""
tell application "Safari"
set safari_windows to the front window
repeat with one_window in safari_windows
repeat with one_tab in (tabs of one_window)
set instapaper_save_url to quoted form of ("https://www.instapaper.com/api/add?url=" & (URL of one_tab) & "&username=" & instapaper_username & "&password=" & instapaper_password)
do shell script "curl " & instapaper_save_url