English 中文(简体)
Shell Script to typeset Lilypond files with Textwrangler
原标题:

I need a shell script which will allow me to typeset Lilypond files from TextWrangler (A Mac App). So far I have come up with this:

#!/bin/sh
/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1

which, of course, doesn t work. (That s why I m at Stack Overflow.)

When I run that script from the shebang menu in TextWrangler, I get this output:

/Applications/LilyPond.app/Contents/Resources/bin/lilypond: option faultpaper,
--output   requires an argument

What gives?

I m running Snow Leopard, TextWrangler, and Lilypond. Help appreciated.

问题回答

EDIT: Found a way to get the document path in a Unix Script launched by TextWrangler, so I ve rewritten this.

There are multiple ways to work with scripts in TextWrangler through the #! menu, and I m not sure which one you re trying to use. It looks, though, like you re trying to create a Unix Script to convert your LilyPond document.

As your error hints, Unix Scripts unfortunately aren t given any arguments at all, so $1 will be empty. However, it turns out that recent versions of BBEdit/TextWrangler do set some environment variables before running your script (see BBEdit 9.3 Release Notes and scroll down to Changes). In particular, you can use the following environment variable:

BB_DOC_PATH            path of the document (not set if doc is unsaved)

So, save this script to ~/Library/Application Support/TextWrangler/Unix Support/Unix Scripts and you should be good to go.

Other ways you might be trying to do this that don t work well:

  • Using a Unix Filter: to do this you would have to select all of your LilyPond code in the document, and it would be saved into a temporary file, which is passed as an argument to your script. OK, so that gets you an input filename, at the cost of some hassle. But then the output of that script (i.e. the LiiyPond compiler output) by default replaces whatever you just selected, which is probably not what you want. Wrong tool for the job.
  • Using #! → Run on a LilyPond file: This involves putting a #! line at the top of your file and having TextWrangler attempt to execute your file as a script, using the #! as a guide to selecting the script interpreter. Unfortunately, the #! line only works with certain scripting languages, and LilyPond (not quite a scripting language) isn t one of them. This is what Peter Hilton is trying to do, and as he notes, you will get LilyPond syntax errors if you try to add a #! line to the top of a LilyPond file. (If you re curious, there is technically a way to get #! → Run to work, which is to embed your LilyPond code inside an executable shell or perl script, using here-document syntax. But this is a gross hack that will quickly become unwieldly.)

There are a few limitations to the script linked above:

  • It doesn t check to see whether you saved your document before running LilyPond. It would be nice to have TextWrangler automatically save before running LilyPond.
  • It can t take snippets of text or unsaved documents as input, only saved documents.

You can make more sophisticated solutions that would address these by turning to AppleScript. Two ways of doing this:

  • Create a script that s specific to TextWrangler and drop it in ~/Library/Application Support/TextWrangler/Scripts. It then shows up in the AppleScript menu (the weird scrolly S), or you can get at it by bringing up Window → Palettes → Scripts. I believe two folks out there have gone down this path and shared their results:
  • Create a Mac OS Service, which would potentially be a method that would be reusable across just about any text editor. This was how we used to compile Common Music files way back in the NeXT days, so I can testify to its elegance. I don t have a good up-to-date example of this, unfortunately.

Good question. It actually runs Lilypond on my system if you do this:

#!/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1

… but fails because # is not a line-comment character so Lilypond tries to parse the line.

Surrounding it with a block comment fails because TextWrangler cannot find the ‘shebang’ line.

%{
#!/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1
%}

An alternative is to use Smultron 3, which lets you define commands that you can run with a keyboard shortcut.





相关问题
Lilypond snippet for a separate coda

我不希望李利美,不要在乐团音乐的不常见之处,而是从狙击手存放处失踪,而不要看我的搜索词。 它基本上是除......外被 co死的 block脚石。

Shell Script to typeset Lilypond files with Textwrangler

I need a shell script which will allow me to typeset Lilypond files from TextWrangler (A Mac App). So far I have come up with this: #!/bin/sh /Applications/LilyPond.app/Contents/Resources/bin/...

Changing all the colors in Lilypond

In Lilypond I can change the color of one type of object with a line like override Staff.Clef # color = #(rgb-color 0.4 0.5 0.6) I d like to have everything in the same (non-default) color, but I ...

Lilypond Mac OS X build issue

I am trying to do a clean build of Lilypond on a clean install of Mac OS X. Dependencies have been installed using Brew. I do ./configure && make all in the Lilypond dir. It gets through the ...

Lilypond: Customize bar lines, recursively, automatically?

I m working on Carnatic music scores that involve complex time signatures, that will require modified bar lines Pattern for barlines for: 8/4 beats: 1 2 3 4 (dashed bar here) 5, 6 (Dotted Bar) 7, ...

Coloring notes in Lilypond by pitch

lilypond can color notes in a arbitrary way using override NoteHead # color = #red c with the default color is black. But I like to color all notes by pitch, so that my kids can more easily learn ...

热门标签