Save Open Safari Tabs


#1

Hi everyone. Can anyone out there help me create a Shortcut or some other functionality that will take all open Safari Tabs and save them in Instapaper?

I mostly have a lot of tabs open in Safari on MacOS so I don’t know how a Siri Shortcut would help there. But maybe someone knows of another way to save all open tabs in Instapaper?

Thanks :slight_smile:


#2

I don’t think you can loop through open Safari tabs on iOS, because of sandboxing. But for the Mac here’s a simple AppleScript to save everything to Instapaper. Instapaper has a fairly simple API, so just a cURL request with the URL, username and password should be enough. (You can get more fancy of course, might be a fun exercise.)

-- 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"
	activate
	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
		end repeat
	end repeat
end tell

You can run this AppleScript from all sorts of places by the way. I often run an AppleScript to save the open Chrome tabs of the current window to a Markdown file, via Alfred.


#3

Thanks a lot! I also use Alfred. Can you tell me how to set it up and run it from Alfred? I haven’t tried the script yet but I will do it tonight.


#4

Save it as an application from script editor and launch it like any app in Alfred?


#5

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. :slight_smile:

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! :slight_smile:

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)

on alfred_script(q)
	-- 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"
		activate
		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
			end repeat
		end repeat
	end tell
end alfred_script

#6

Thanks. I don’t see "add an “Run Applescript” anywhere. Where do I find it?


#7

Did you try this?

Could you post a screenshot of what you see if that does not reveal the option?


#8


#9

My bad, I skipped a step!

You need to give it a name first, something like “Save Safari Tabs to Instapaper” should do. :slight_smile:

Press “Save” and follow the rest of the instructions.