Updated Autolily Script


1 #!/usr/bin/ruby
2 #===============================================================================================================#
3 # Program name: Autolily #
4 # LICENSE: PUBLIC DOMAIN #
5 # This program takes 1 argument, the name of a lilypond file (*.ly), and watches it for changes every 1 second. #
6 # If there has been any change, it simply calls lilypond on it to create a new .pdf/.ps/.midi of it. #
7 # #
8 # Place this script somewhere, like in ~/scripts #
9 # Then, open up a terminal and call it like so: ~/scripts/autolily.rb [file] #
10 # [file] must be a LilyPond file (.ly), but it can be located anywhere — i.e., you may include paths in your #
11 # file, such as “~/sheet-music/classical/bach2.ly” or “../../bach3.ly”. #
12 # #
13 # You might want to do a “sudo ln -s” of autolily.rb to one of your system’s $PATH directories (e.g., /usr/bin) #
14 # to avoid typing out the path to autolily.rb every time you use it. Continuing the example from above, #
15 # something like “sudo ln -s ~/scripts/autolily.rb /usr/bin/autolily” should do (make sure that #
16 # /usr/bin/autolily does not exist already, as the above comman will overwrite that file if it exists). #
17 # #
18 # Now you can just do: #
19 # #
20 # autolily [file] #
21 # #
22 # from anywhere in your system! #
23 # #
24 # To exit, press CTRL-C. #
25 #===============================================================================================================#
26
27 if ARGV.size > 0
28 file_data_orig = “”
29 file = ARGV.shift
30 pathsize = file.split(“/”).size
31 ls_call = “ls –full-time”
32
33 # make sure that the “file” variable is a filename, and not mixed with its path
34 if pathsize > 1
35 path_to_file = file.split(“/”).first(pathsize – 1).join(“/”)
36 file = file.split(“/”).last
37 ls_call < 1
66 `lilypond “#{path_to_file}/#{file}”`
67 else
68 `lilypond “#{file}”`
69 end
70 file_data_orig = file_data_new
71 end
72 sleep 1
73 end
74 else
75 puts “No .ly file specified.\n”
76 end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s