'Rename Terminal Tabs Automatically with command
I am trying to rename opened terminal tabs in OSX, but I can only change the Terminal title with the code below. Is there a way to change the Tab title with command? I am using osascript with python 2.7.
name = """osascript -e 'tell application "Terminal" to set custom title in selected tab of the front window to "script_1"'"""
os.system(name)
Manually: Shell > Edit Title(SHIFT+COMMAND+I) > Tab Title
Solution 1:[1]
Simply passing the following sequence to os.system should work:
>>> import os
>>> tab_title = 'echo "\033]0;%s\007"' % "hello world!"
>>> os.system(tab_title)
0
>>>
Solution 2:[2]
I found this one very useful, because it doesn't print unnecessary output to stdout unlike my experiments with subprocess or os.system which resulted in unwanted appearance of '-e' in console.
import sys
sys.stdout.write("\x1b]2;%s\x07" % 'TAB name')
Solution 3:[3]
This should do:
title='Customized title for TAB'
os.system('echo -n -e "\033]0;{}\007"'.format(title))
Solution 4:[4]
Here is the solution with using keys to open inspector, change title and close the inspector. Because according to my research there is no option to change tab title on OSX with using a ready apple script.
It works great, so no need to wait for Apple to release this option.
tabinspector = """osascript -e 'tell application "System Events" to keystroke "i" using {shift down,command down}'"""
pressstab = """osascript -e 'tell application "System Events" to keystroke Tab'"""
title = """osascript -e 'tell application "System Events" to keystroke "yourtitlehere"'"""
pressesc = """osascript -e 'tell application "System Events" to key code 53'"""
os.system(tabinspector)
os.system(pressstab)
os.system(title)
os.system(pressesc)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sf89 |
| Solution 2 | Matúš Košút |
| Solution 3 | |
| Solution 4 |
