Note that you can always just trigger operation manually when starting process 2, so you can get by without a script, though it is not convenient.
Some ideas:
On 2023-02-22, Saurav writes: I have optimized the MacOS script for running and testing our Blockchain program. Save the below code snippet in ".scpt" file extension and place it in the same directory as your "Blockchain.java" file along with the Gson jar. To execute the script, open it using the Apple script editor and execute it through "run" button provided in the dialog. Please let me know if there is any problem while running this script. --Start Script set processcount to 3 --Set process count as required (Default set to 3) tell application "Finder" --Fetching the current path set currentPath to (do shell script "dirname " & quoted form of (POSIX path of (path to me) as string)) as string tell application "Terminal" if not (exists window 0) then reopen activate set targetWindow to 0 do script "cd " & currentPath in window 0 --Setting path to current path do script "javac -cp \"gson-2.8.2.jar\" *.java" in window 0 --Compiling Blockchain do script "java -cp \".:gson-2.8.2.jar\" Blockchain 0" in window 0 --Executing Blockchain first process as argument "0" delay 1 repeat with counter from 1 to (processcount-1) --Looping through the counter and opening different terminal each repeat with counter from 1 to (processcount-1) --Looping through the counter and opening different terminal each for given count do script "cd " & currentPath delay 0.5 do script "java -cp \".:gson-2.8.2.jar\" Blockchain "&counter in front window delay 1 end repeat end tell end tell --End Script ------------ In Windows, the ".;gson..." part is valid. In Unix systems, this needs to be ".:gson..." with a colon, and not a semicolon. -- Thanks Kyle!Thanks Riddhi: IntelliJ script for running multiple processes.
Thanks David Maciulis!: I figured out a very easy way of starting multiple java programs using AppleScript. 1) Create a text file that has .scpt extension --> myScript.scpt 2) Copy/paste the script below (don't forget to change the path) 3) Run the script in terminal --> osascript myScript.scpt If anyone has any ideas how to improve the script below, please let me know. Script: tell application "Terminal.app" activate set targetWindow to 0 do script "cd /Users/davidmaciulis/DePaul/DistributedSystems/Assignments/Blockchain/ && java bc 0" tell application "System Events" to keystroke "t" using command down do script "cd /Users/davidmaciulis/DePaul/DistributedSystems/Assignments/Blockchain/ && java bc 1" in window 0 delay 0.3 tell application "System Events" to keystroke "t" using command down do script "cd /Users/davidmaciulis/DePaul/DistributedSystems/Assignments/Blockchain/ && java bc 2" in window 0 end tell
Another script. Thanks Chadwick! If the new tab isn't in the correct directory then just re-add "cd /your/directory/here/" before the java command to solve that. //start script tell application "Terminal" activate set targetWindow to 0 do script "cd /Users/Chad/Documents/DePaul/CSC435/assignments/Blockchain/" in window 0 do script "javac -cp \"gson-2.8.2.jar\" *.java" in window 0 do script "java -cp \".:gson-2.8.2.jar\" Blockchain 0 " in window 0 delay 0.3 tell application "System Events" to keystroke "t" using command down do script " java -cp \".:gson-2.8.2.jar\" Blockchain 1 " in front window delay 0.3 tell application "System Events" to keystroke "t" using command down do script " java -cp \".:gson-2.8.2.jar\" Blockchain 2 " in front window end tell //end script If you have any questions or suggestions, feel free to reach out! EDIT: I edited the command for running to include ".:gson-2.8.2.jar\" as it is required
Thanks Kaz! I figured out a super clunky way of getting [Multiple Scripts] going [on Mac]. Hopefully it helps someone else - I'm sure there are lots of ways of improving this, but here's what I came up with. The path to my Blockchain.java file is "Desktop/'CSC_435'/Blockchain", so you can change that depending on what your folder structure looks like osascript <--java.xml.bind Blockchain 0" end tell tell app "Terminal" do script "cd Desktop/'CSC 435'/Blockchain && java --add-modules --> --java.xml.bind Blockchain 1" end tell tell app "Terminal" do script "cd Desktop/'CSC 435'/Blockchain && java --add-modules --> --java.xml.bind Blockchain 2" end tell EOF
Thanks Randy: 2018-02-11 I started searching around on iTerm's website and found a scripting reference page. https://www.iterm2.com/documentation-scripting.html After creating a new profile called BlockChain to direct the new terminals to the correct working directory in iTerm I used the following script that will get all 3 processes running in separate windows and it works like the demo in class. Save the below into scriptName.scpt tell application "iTerm2" create window with profile "BlockChain" command "java bc 0" create window with profile "BlockChain" command "java bc 1" create window with profile "BlockChain" command "java bc 2" end tell You can then run > osascript scriptName.scpt This isn't pretty, but it works for the demo code and I think with some small tweaks should work for the assignment. and Thanks Matt: 2018-02-11 Another solution...not pretty but functional Copy below to allbat.sh run chmod 700 on allbat.sh run ./allbat.sh at command line #!/bin/sh osascript <