Skip to content

Instantly share code, notes, and snippets.

@chsh
Last active March 14, 2021 01:35
Show Gist options
  • Save chsh/010fe73cb19f4defc84b to your computer and use it in GitHub Desktop.
Save chsh/010fe73cb19f4defc84b to your computer and use it in GitHub Desktop.
Save webarchive using webloc file.
#!/usr/bin/env ruby
require 'tmpdir'
require 'shellwords'
webloc_file = ARGV[0]
webloc_ext = File.extname(webloc_file)
webarchive_file = webloc_file.gsub(/#{webloc_ext}$/, '.webarchive')
url = nil
tags = nil
Dir.mktmpdir do |dir|
tmp_js_file = File.join(dir, 'tmp.js')
system('/usr/bin/plutil', '-convert', 'json', webloc_file, '-r', '-o', tmp_js_file)
url = `/usr/local/bin/jq .URL #{tmp_js_file}`.chomp
tags = `/usr/local/bin/tag -lN #{webloc_file.shellescape}`.chomp
end
system('/usr/local/bin/webarchiver', '-url', url, '-output', webarchive_file)
system('/usr/local/bin/tag', '-a', tags, webarchive_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment