使用 Textwrangler 排版 Lilypond 文件的 Shell 脚本
我需要一个 shell 脚本,它允许我从 TextWrangler(Mac 应用程序)排版 Lilypond 文件。 到目前为止,我已经想出了这个:
#!/bin/sh
/Applications/LilyPond.app/Contents/Resources/bin/lilypond -o $1
当然,这是行不通的。 (这就是我在 Stack Overflow 工作的原因。)
当我从 TextWrangler 中的 shebang 菜单运行该脚本时,我得到以下输出:
/Applications/LilyPond.app/Contents/Resources/bin/lilypond: option faultpaper,
--output'' requires an argument
给出了什么?
我正在运行 Snow Leopard、TextWrangler 和 Lilypond。 帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:找到了一种在 TextWrangler 启动的 Unix 脚本中获取文档路径的方法,所以我重写了它。
通过 #! 菜单,可以通过多种方式在 TextWrangler 中使用脚本,但我不确定您要使用哪一种。不过,看起来您正在尝试创建一个 Unix 脚本来转换您的 LilyPond 文档。
正如您的错误提示,不幸的是,Unix 脚本根本没有给出任何参数,因此
$1
将为空。然而,事实证明,最新版本的 BBEdit/TextWrangler 在运行脚本之前确实设置了一些环境变量(请参阅BBEdit 9.3 发行说明 并向下滚动到更改)。特别是,您可以使用以下环境变量:因此,将此脚本保存到
~/库/应用程序支持/TextWrangler/Unix 支持/Unix 脚本
,您应该可以开始了。您可能尝试执行此操作的其他方法效果不佳:
#!
行,并让 TextWrangler 尝试使用 < code>#! 作为选择脚本解释器的指南。不幸的是,#!
行仅适用于某些脚本语言,而 LilyPond(不完全是脚本语言)不是其中之一。这就是 Peter Hilton 正在尝试做的事情,正如他所指出的,如果您尝试将 #! 行添加到 LilyPond 文件的顶部,您将收到 LilyPond 语法错误。 (如果您好奇,从技术上讲,有一种方法可以让 #! → Run 工作,即使用此处文档语法将 LilyPond 代码嵌入到可执行 shell 或 perl 脚本中。但是这是一个粗俗的黑客行为,很快就会变得难以控制。)上面链接的脚本有一些限制:
您可以通过使用 AppleScript 来制定更复杂的解决方案来解决这些问题。有两种方法可以实现此目的:
~/Library/Application Support/TextWrangler/Scripts
中。然后它会显示在 AppleScript 菜单中(奇怪的滚动 S),或者您可以通过调出窗口 → 调色板 → 脚本 来获取它。我相信有两个人已经走了这条路并分享了他们的结果: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: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:
#!
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:
You can make more sophisticated solutions that would address these by turning to AppleScript. Two ways of doing this:
~/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:好问题。如果您这样做,它实际上会在我的系统上运行 Lilypond:
...但会失败,因为
#
不是行注释字符,因此 Lilypond 会尝试解析该行。用块注释包围它会失败,因为 TextWrangler 找不到“shebang”行。
另一种方法是使用 Smultron 3,它可以让您定义您需要的
命令
可以使用键盘快捷键运行。Good question. It actually runs Lilypond on my system if you do this:
… 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.
An alternative is to use Smultron 3, which lets you define
commands
that you can run with a keyboard shortcut.