cmc-csci046 icon indicating copy to clipboard operation
cmc-csci046 copied to clipboard

apple script : open up 2 terminal windows / log into the lambda server / increase font size

Open buffeinstein opened this issue 2 years ago • 1 comments

I wrote an Apple Script to open up two terminal windows, log into the lambda server, and increase the font size. I’m running Monterey. I thought I would share my steps in case others want to try:

  1. Open Script Editor on your Mac. You can find it in the Utilities folder within the Applications folder.
  2. Copy and paste your working AppleScript code into a new document.

Here’s the code:

tell application "Terminal"
	
	activate
	do script "<ssh login>"
	delay 1
	tell application "System Events" to keystroke "<password>"
	delay 1
	tell application "System Events" to keystroke return
	delay 1
	tell application "System Events" to keystroke "clear"
	delay 1
	tell application "System Events" to keystroke return
	delay 1
	
	activate
	do script "<ssh login>"
	delay 1
	tell application "System Events" to keystroke "<password>"
	delay 1
	tell application "System Events" to keystroke return
	delay 1
	tell application "System Events" to keystroke "clear"
	delay 1
	tell application "System Events" to keystroke return
	delay 1
	
	set font size of window 1 to 16
	set font size of window 2 to 16
	
end tell
  1. Click on "File" in the menu bar and choose "Save" or press "Command + S" on your keyboard.
  2. In the "Save As" dialog box, give your script a name and choose "Application" as the file format.
  3. Choose a location to save your script and click the "Save" button.
  4. Go to System Preferences > Security & Privacy > Privacy > Accessibility. Click the lock in the bottom-left corner, and add your application.

I added the app to my desktop so that I can just click it and let it do its thing. Done!

If you’re having trouble with permissions, try running this in your terminal:

$ tccutil reset AppleEvents

I don't know if it's safe to write scripts with your password, but... YOLO?

buffeinstein avatar Mar 04 '23 10:03 buffeinstein

If you know how to build upon this application, please let me know :)

Here were some things I tried and couldn’t figure out:

  • Adding a keyboard shortcut for this application
  • Automatically having the two terminal window tiles take up the whole screen

Also, sometimes the above code opens up a third terminal, but doesn’t run the commands in it. The other two terminals work as normal.

To edit the application:

  1. Locate the application file in Finder.
  2. Right-click on the application file and select "Show Package Contents" from the context menu.
  3. In the opened folder, navigate to the "Contents" folder and open the "Resources" folder.
  4. Find the file with the extension ".scpt" and double-click to open it in Script Editor.
  5. Make the necessary changes to the script and save the file.
  6. Close the Script Editor and the application file package.
  7. Run the modified application and test if it works as expected.

Note that if you made any changes to the script that require additional permissions, you will need to grant those permissions again when running the modified application.

buffeinstein avatar Mar 04 '23 10:03 buffeinstein