苹果脚本oneliner
是否可以将 applescript 行合并为一个(在 ruby 中可以使用 ;
来完成)?
Is it possible to join applescript lines into one (in ruby it can be done using ;
)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
并不真地。最多可以做的就是采用一个简单的
if-then
语句并将其变成一行......变成...
如果您要包含
osascript 命令在 shell 脚本中,那么多行脚本必须用
-e
分隔...但这就是它的范围。 Applescript 文件不像大多数其他编程语言那样是简单的文本文件(不幸的是),我们必须依靠其专门的编辑器进行行管理。
Not really. The most that can be done is to take a simple
if-then
statement and make it into one line......becomes...
If you were to include the
osascript
command in a shell script, then multiple line scripts must delimited with-e
...But that's about the extent of it. Applescript files aren't straightforward text files like most other programming languages (unfortunately) and we have to rely on its specialized editors for line management.
这取决于你的代码。
当您使用 AppleScript 进行 GUI 脚本编写时,您通常可以将一堆嵌套的告诉块编写为一行。
例如这些嵌套的告诉块:
它们也可以写为:
It depends on your code.
When you use AppleScript for GUI scripting, you can often write a bunch of nested tell blocks as one line.
For example these nested tell blocks:
They could also be written as:
如果您确实想避免
-e
并将所有内容强制放在一行上,您可以通过echo
推送所有内容,其中
"
变为\\"
和换行符变为\n
。If you really want to avoid
-e
and force everything on one line you can push everything throughecho
Where
"
become\\"
and newlines become\n
.我已将 AppleScript 从块格式重新排列为单行格式,如下所示:
块格式
单行格式
osascript -e "tell application \"\" to activate & open location \"< ;url>\"";
I have re-arranged AppleScript from a block format, to a single line format as such:
Block format
Single line format
osascript -e "tell application \"<application>\" to activate & open location \"<url>\"";