Coder Social home page Coder Social logo

safari-webarchiver's Introduction

safari-webarchiver

This tool creates Safari webarchive files on the command line. This gives you an offline archive of web pages, which can be stored and backed up independently of any cloud services.

$ save_safari_webarchive "https://example.com" "example.webarchive"

These archives are the same as those created by the File > Save As… menu item, but now you can create them programatically and in bulk.

How it works

It opens the given URL in a WKWebView, calls createWebArchiveData to create a webarchive file, and saves it to disk. That's the core workflow, and then there's a bunch of error handling around that.

For a more detailed explanation of this code, see https://alexwlchan.net/2024/creating-a-safari-webarchive/

Installation

Install from source

  1. Install the Xcode Command Line Tools

  2. Download the save_safari_webarchive.swift script from this repo

  3. Compile the script into a binary:

    $ swiftc save_safari_webarchive.swift
  4. Copy the compiled binary save_safari_webarchive to somewhere in your PATH.

Install a compiled binary

  1. Find the latest GitHub release
  2. Download the zip file which is appropriate for your system (Intel = x86_64, Apple Silion = aarch64)
  3. Open the zip file, and add the save_safari_webarchive app to your PATH

The app is just a compiled version of the Swift script. It isn't notarised, so when you run it, you may get a warning that this app is from an unidentified developer. You can get around this by right-clicking the app icon in Finder, and choosing Open from the shortcut menu.

Usage

Run the script passing two arguments: the URL you want to archive, and the path where you want to save the webarchive file.

For example, this command will save the URL to this GitHub repo to safari-webarchiver.webarchive:

$ save_safari_webarchive "https://github.com/alexwlchan/safari-webarchiver" "safari-webarchiver.webarchive"

Acknowledgements

This is partially inspired by a similar script written in 2008 by newzealandpaul.

safari-webarchiver's People

Contributors

alexwlchan avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.