如何将复杂的 applescript 转换为终端的单行命令
我有一个复杂的 AppleScript,由于某些原因必须作为单行命令执行。我的脚本看起来像:
tell application "Finder"
tell disk "'myDiskName'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 968, 421}
close
open
eject
end tell
end tell
我确实使用终端执行脚本:
echo '<SCRIPT>' | osascript
其中是上面的多行脚本 - 并且工作得很好。现在,更具体地说,我希望使用 ant-task 运行此脚本,例如:
<exec executable="echo">
<arg line="'<SCRIPT>' | osascript" />
</exec>
由于是多行,因此它会以某种方式被忽略/不执行,但它也不会引发异常。我看到两种解决方案:要么是更可取的单行命令,要么是被调用的独立 applescipt。事情是这样的:上面的脚本需要一些动态变量,这些变量必须在运行时从 antscript 生成 - 因此动态创建脚本可能不是一个选择。
I have a complex AppleScript that for some reasons has to be executed as a single line command. My Script looks like:
tell application "Finder"
tell disk "'myDiskName'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 100, 968, 421}
close
open
eject
end tell
end tell
I do execute the script using terminal by:
echo '<SCRIPT>' | osascript
where the is the multiline script above - and that works absolutely fine. Now, to be more specific, I want this script to be run using an ant-task, like:
<exec executable="echo">
<arg line="'<SCRIPT>' | osascript" />
</exec>
Since is multiline, it somehow gets ignored / not executed, but it doesn't throw an exception either. I see two solutions: either a single line command, which is preferable, or a standalone applescipt that gets called. Here's the thing: the script above needs some dynamic variables, that have to be generated from the antscript on runtime - so creating the script on the fly might not be an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定“蚂蚁任务”是什么,但要创建一个单行代码,请这样做...
换句话说,每一行前面都有一个“-e”,并且您希望引用该行。
I'm not sure what an "ant-task" is but to create a one-liner do it this way...
In other words, every line gets a "-e" in front of it and you want the line quoted.
如果 AppleScript 应直接嵌入到 Ant 构建脚本中,最易读的解决方案是将脚本包装到 CDATA 部分。
然后,您可以定义一个 Ant 宏,通过其
inputstring
参数将脚本数据传递给exec
任务:If the AppleScript should be embedded directly into the Ant build script, the most readable solution is to wrap the script into a CDATA section.
You can then define an Ant macro which passes the script data to the
exec
task via itsinputstring
parameter: