#iTerm needs to be in the front for key presses to register. Set command to "echo \"" & oneline & "\" | grep -o \"" & searchString & "\" | wc -l" If length of aRecord is greater than 0 then Set allRecords to paragraphs of terminalContents Log "terminal contents: " & terminalContents I hammered out a workaround that actually seems to work pretty well, here it is for anyone who comes after me: on grepCountsFor(searchString) At that point, I decided that applescript or iTerm's applescript API is just too opaque. What is this stuff? Why don't I see what I expect, which is something like this: Last login: Fri Jun 10 18:18:22 on got this to work for a good 3-5 times in a row, but as soon as I edited my script again, it started returning that session ID stuff. #do shell script "echo " & myvar & " > ~/some_file.txt"Īs you can see, I've tried several different things, "contents" seemed like the most promising solution according to the documentation, but crazy stuff comes out, like this: session id "0986F3BD-D2AF-480F-B517-AB7A43B2A0C4" of tab 3 of window id "window-1" of application "iTerm" # Since we just created the tab, there should only be one session right now. Set newTab to (create tab with default profile) # Create a new tab, which will create a new session inside
Luckily, iTerm v3.X has a bunch of cool AppleScript stuff:īut I'm having a lot of trouble reading the contents of the terminal session. Long story short, instead of using delays and sending text, I'd like to poll the contents of the current session and enter usernames/passwords/tokencodes as soon as the prompt for them appears.
Here is the full script: #!/usr/bin/env python3.7Īpp = await iterm2.I am working on an Applescript to make logging into 2-factor authentication domains a little easier. Now the current tab’s scrollback should be cleared every 10 seconds!.Open the tab where you want to execute the script and press Shift + Cmd + O (shortcut for Open Quickly) and type scroll and you should see the new script.
Paste the following code in the text editor opened and save.Choose the default location and type clear_scrollback_on_schedule for the name.Scripts -> Manage scripts -> New Python script.This will ensure me that the last re-compilation step is the only one shown on the view. You can customize the filename in Preferences > Advanced > Format for automatic session log filenames. File names are formatted as .RandomNumber.log. I wrote a small script that will clear the scrollback of the current tab session every 10 seconds. Automatically log session input to files in: If enabled, every sessions output will be logged to a file in the specified directory.
Since every output looks the same, it wasn’t really clear if my change has been re-compiled or not. For every change, webpack recompiles the modified files and adds it to the output. Here's what I've got so far: on run Start or activate iTerm tell application 'iTerm' activate tell the first window Create a new tab, which will create a new session inside set newTab to (create tab with default profile) tell newTab Since we just created the tab, there should only be one session right now. I was using it today to run a webpack watch command on my 2nd monitor.
It is highly customizable and has API support for hackability. ITerm2 is my default terminal and have been using it for close to 8 years now.