如何将 bash 的命令替换和管道转换为 Applescript?

发布于 2024-12-02 04:50:58 字数 640 浏览 1 评论 0原文

我需要帮助将这个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紧拥背影 2024-12-09 04:50:58

我(现在)看到的唯一问题是将 do shell script 更改为 do script。除此之外,您已经正确启动了它。我假设您想将文件引用传递给 shell 脚本。这相当简单...

set these_files to (choose file with multiple selections allowed)
repeat with this_file in these_files
    tell application "Finder" to if the name extension of this_file is "class" then my do_shell_script(this_file)
end repeat

on do_shell_script(this_file)
    tell application "Terminal" to activate --makes 'Terminal' the frontmost application
    --'do shell script ...' goes here
    --To refer to a file/folder for a 'do shell script', do something like the command below...
    --do shell script "mdls -name kMDItemLastUsedDate " & quoted form of the POSIX path of this_file
end do_shell_script

The only issue I'm seeing (right now) is to change do shell script to do 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...

set these_files to (choose file with multiple selections allowed)
repeat with this_file in these_files
    tell application "Finder" to if the name extension of this_file is "class" then my do_shell_script(this_file)
end repeat

on do_shell_script(this_file)
    tell application "Terminal" to activate --makes 'Terminal' the frontmost application
    --'do shell script ...' goes here
    --To refer to a file/folder for a 'do shell script', do something like the command below...
    --do shell script "mdls -name kMDItemLastUsedDate " & quoted form of the POSIX path of this_file
end do_shell_script
〃温暖了心ぐ 2024-12-09 04:50:58

我根本不了解 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 with java -jar ....)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文