How to programmatically set Mac OS X 10.6 program header?

I am trying to learn Applescript, as I would like to end up programmatically setting the tab title in the terminal in any context in which I am currently working. It should be a simple task, and I got 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 title, the title of all other tabs is also set. However , if I right-clicked and checked the tab and then set the title manually on this tab, its title will not be affected when my code runs, and the title that I manually printed remains. It is as if the title displays custom title property is not being read, or perhaps this property is not doing what I think it is doing.

How to set the title of one tab to a custom value?

+4
source share
6 answers

I am executing a script from the terminal itself, you can use a simple echo , for example:

echo -n -e "\033]0;Tech-Recipes rules\007"

This event works if you place it inside $PS1 so that it changes every time the invitation is rendered.

source: How to customize Mac OS X 10.6 program header programmatically?

+6
source

I just tried this and it worked fine:

 tell application "Terminal" set custom title of tab 2 of window 1 to "beta" set custom title of tab 1 of window 1 to "alpha" end tell 

I admit that I did not use 10.6, so Apple changed it.

+2
source

This property does not do what you think. Setting a custom title for one tab applies to all tabs in all windows for this code:

 tell application "Terminal" tell window 1 set title displays custom title of tab 1 to true set custom title of selected tab to "foo" end tell tell window 2 set title displays custom title of tab 2 to true set custom title of selected tab to "bar" end tell end tell --> RESULT: All tabs in all windows show "bar" 

I wonder if this is due to a header related to the environment - that is, bash , csh , zsh , ksh , and not to individual tabs. Even if I leave the Terminal and return, the β€œbar” is still displayed everywhere. I freely admit that I do not know enough about how the CL interface works to know for sure.

At the same time, if you are studying Applescript, I would advise you to learn it with something less fun, like Finder or something like that. There are tons of more useful things you can do there than in the terminal with Applescript.

+1
source

There are some strange behaviors around these commands when capturing the correct window / tab, but this ultimately works for me in 10.5.8 (Terminal v2.0.2)

 tell application "Terminal" do script set currWin to index of first window tell window currWin set custom title of first tab to "A Custom Title" end tell set current settings of window currWin to settings set "Grass" end tell 

The key point here is that the do script opens a new terminal window, thereby forcing it to be β€œfirst” (the do script also returns the created tab index, but I could not use it).

The custom title then applies only to this window. Also added a line to set the profile for the terminal tab.

(Ref: AppleScript to open a named terminal )

Additional Example of strange behavior: deleting the do script causes the custom title to be applied to all windows, but only one window receives a change in the set of settings!

+1
source

As in Mac OS X Lion 10.7, Terminal sets only the custom title property of the target tab / window instead of changing the settings profile (which affects all terminals with this profile). Prior to 10.7, most, but not all terminal properties apply only to the target terminal; however, some of them have been applied to the settings profile used by the terminal. They were changed in 10.7 to affect only the target terminal.

+1
source

I have been looking for this for a while, and like the @tponthieux mentioned in his comment, all of these scripts change the title of the terminal window, not the tab title. Unfortunately, it seems there is no way to change the title of the tab with the finished apple script, so I did it with the keys and it works without problems on OSX El Capitan.

 tell application "Terminal" activate tell application "System Events" keystroke "i" using {shift down,command down} keystroke Tab keystroke "yourtitlehere" key code 53 end tell 
+1
source

All Articles