How can I keep the session name fixed in iterm2 tab created by applescript?
0
votes
0
answers
105
views
I have been using iterm2 and I created an
If I click on it, it switches to locked, which provides the behaviour I want, by prefixing the session name in the tab title.
**Question**: How can I set this lock via applescript?
Thank you!
applescript
to automate the process of opening some tabs I need to work in my project. I opens a few tabs, moves to directories, run a few statements (git pull
, npm install
, etc..) and set the session name (tab name). See the example:
#!/usr/bin/osascript
tell application "iTerm2"
tell current window
create tab with default profile
set backendTab to current session
end tell
tell backendTab
write text "cd /Users/felipe/projects/backend && git pull && npm install"
write text "clear"
set name to "backend"
end tell
end tell
And I call it from a function in my ~/.zshrc
function dev() {
osascript dev.scpt
}
It works, but the problem is when I run any command in these tabs such as npm start
to run my app, it changes the tab name. If I right click on the tab, I can see the session name set, and a unlocked icon next to it:


Asked by Felipe Oriani
(101 rep)
Feb 26, 2025, 07:43 PM
Last activity: Feb 27, 2025, 10:34 AM
Last activity: Feb 27, 2025, 10:34 AM