-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in case I need to convert mind maps in the future
- Loading branch information
1 parent
68cdb72
commit 1fdc727
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "optparse" | ||
require "pathname" | ||
|
||
Options = Struct.new(:help, :filenames) | ||
|
||
def main | ||
options = Options.new(help: false, filename: nil) | ||
op = OptionParser.new do |opts| | ||
opts.banner = <<-BANNER | ||
Usage: mindnode-to-opml filename" | ||
filename accepts MindNode files or "package" directories. | ||
BANNER | ||
opts.separator "" | ||
opts.separator "Options: " | ||
|
||
|
||
opts.on("-h", "--help", "Print this help message") do |h| | ||
options.help = true | ||
end | ||
end | ||
|
||
op.parse! | ||
filenames = ARGV | ||
|
||
filenames.each do |filename| | ||
path = Pathname.new(filename) | ||
if path.exist? | ||
convert(path) | ||
else | ||
$stdout.puts "#{filename}: not found" | ||
exit -1 | ||
end | ||
end | ||
end | ||
|
||
def convert(path) | ||
input = path.expand_path | ||
output = (path.dirname + path.basename(".*")).to_s + ".opml" | ||
|
||
osa_script = <<~JS | ||
const MindNode = Application("MindNode") | ||
var doc = MindNode.open("#{input}") | ||
const filename = "#{output}" | ||
doc.export({to: filename, as: "OPML"}) | ||
JS | ||
statement_lines = osa_script | ||
.split("\n") | ||
.map { |l| "-e '#{l}'" } | ||
.join(" ") | ||
cmd = "osascript -l JavaScript #{statement_lines}" | ||
|
||
puts "#{input} -> #{output}" | ||
Kernel.system(cmd, exception: true) | ||
end | ||
|
||
if __FILE__ === $0 | ||
main | ||
end |