How can I convert bash's command substitution and pipe to an 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 usin开发者_如何学Cg 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?
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
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 ...
.)
精彩评论