-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmindnode-to-opml
executable file
·61 lines (49 loc) · 1.28 KB
/
mindnode-to-opml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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