I'm trying to learn Applescript as I'd like to, eventually, programmatically set the title of the tab in Terminal to whatever context I'm currently working in. Should be a simple task and I've gotten it almost right I think. This is my experimental code so far...
tell application "Terminal"
activate
set frontIndex to index of the first window whose frontmost is true
tell window frontIndex
set title displays custom title of selected tab to true
set custom title of selected tab to "Bazzy"
end tell
end tell
The problem is that when I set the tab's title, the title of all other tabs also get set. However, if I right-click and inspect a tab and then set the title manually on that tab, its title is not affected when I run my code and the title I manually typed in remains. It's as though the title displays custom title
property is not being read or perhaps this property does not do what I think it does.
How can I set the title of exactly one tab to a custom value?
In the Terminal app on your Mac, choose Terminal > Settings, then click Profiles. In the Profiles list, select a profile. Click Window. Below Title, enter the name you want to appear in the title bar.
In the Terminal app on your Mac, choose Terminal > Preferences, then click Profiles. Do one of the following: Create a new profile: Click the Add button under the profiles list, then enter a name for the new profile. Modify an existing profile: Select the profile you want to modify.
Terminal tabs allow you to access the command line shell on your Mac or a remote server. To create a new Local or Remote terminal click the New Tab button, or choose File > New Remote/Local Terminal. Choosing a Local Terminal will open a shell on your own Mac.
I you're executing the script from the Terminal itself you can use a simple echo
, e.g.:
echo -n -e "\033]0;Tech-Recipes rules\007"
It event works if you put it inside $PS1
so that it changes each time the prompt is rendered.
source: How do I set Mac OS X 10.6 Terminal tab title programmatically?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With