如何将 bash 的命令替换和管道转换为 Applescript?
我需要帮助将这个简单的 shell 脚本转换为苹果脚本。
关键是因为它要在 Automator 工作流程中使用,所以我需要打开终端窗口,而这是使用 shell 脚本无法完成的。
shell脚本如下:
java -classpath `dirname "$1"` `basename "$1" | sed "s/.class//g"`
它获取文件的位置,然后获取文件的名称,然后去掉“.class”的文件扩展名,然后使用Java命令运行它。例如,它会生成以下命令:
java -classpath /users/desktop/ filename
我需要转换此命令,以便它可以与 Applescript 一起使用,这样我就可以在终端窗口中看到应用程序运行。它会像下面这样开始:
on run {input, parameters}
tell application "Terminal"
activate
do shell script "java -classpath path/to/ file"
end tell
end run
如何将文本转换移植到 Applescript?
I need help converting this simple shell script to an apple script.
The point being because it is to be used in an Automator workflow, and so I need the Terminal window to be open, which cannot be done using a shell script.
The shell script is as follows:
java -classpath `dirname "$1"` `basename "$1" | sed "s/.class//g"`
This gets the location of the file, and then the name of the file, and then strips away the file extension of ".class", and then runs it using the Java command. So for example it would generate the following command:
java -classpath /users/desktop/ filename
I need to convert this command so that it works with Applescript so that I can then see the application run in the Terminal window. It would start like the following:
on run {input, parameters}
tell application "Terminal"
activate
do shell script "java -classpath path/to/ file"
end tell
end run
How can I port the text transformation to Applescript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我(现在)看到的唯一问题是将
do shell script
更改为do script
。除此之外,您已经正确启动了它。我假设您想将文件引用传递给 shell 脚本。这相当简单...The only issue I'm seeing (right now) is to change
do shell script
todo script
. Other than that, you've started it correctly. I'm assuming you want to pass (a) file reference(s) to the shell script. It's fairly simple...我根本不了解 AppleScript,但我想您可以简单地在
do shell script
行中调用现有的 shell 脚本,而不是尝试在 AppleScript 中重做字符串操作。注:
看起来您希望能够通过单击(或拖放等)来调用 Java 类。您的方法仅适用于匿名包中的类,即在源代码开头没有任何
package ...;
声明。对于其他人,您可能会尝试找出它们位于哪个包中。我不知道该怎么做。无论如何,可分发程序应该位于 jar 档案中,您应该能够使用java -jar ...
启动它。)I don't know AppleScript at all, but I suppose you could simply call your existing shell script in the
do shell script
line, instead of trying to redo the string manipulation in AppleScript.Note:
It looks like you want to be able to invoke Java classes by click (or drag-n-drop or such). Your method will only work for classes in the anonymous package, i.e. without any
package ...;
declaration in the beginning of the source code. For others, you might try to find out in which package they are. I have no idea how to do this. Distributable programs should be in jar archives, anyway, where you should be able to start it withjava -jar ...
.)