Last active
March 14, 2021 01:35
-
-
Save chsh/010fe73cb19f4defc84b to your computer and use it in GitHub Desktop.
Save webarchive using webloc file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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