Mac Launch terminal window w/ different profile

comatory

macrumors 6502a
Original poster
Apr 10, 2012
736
0
I have a certain default terminal profile (look) that I like to use all the time. However when I use VIM I have a different profile that I have to trigger via preferences in Terminal.app.

What I'd like to have is .command file that would open new terminal window with that profile enabled, so I could just drop the file in dock or launch it via alias in other terminal session.

I could also accept AppleScript solution. Any ideas?
 

kryten2

macrumors 6502a
Mar 17, 2012
996
59
Belgium
Did you try Window Groups? There's also a settings set and current settings in the Terminal dictionary.
 
Last edited:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
I have a certain default terminal profile (look) that I like to use all the time. However when I use VIM I have a different profile that I have to trigger via preferences in Terminal.app.
There is a .vimrc file where you can set colors and things like that for vim, have you looked into that?
 

comatory

macrumors 6502a
Original poster
Apr 10, 2012
736
0
There is a .vimrc file where you can set colors and things like that for vim, have you looked into that?
yes I did that but when you use VIM in terminal you can't adjust text size by adjusting .vimrc file
 

chown33

Moderator
Staff member
Aug 9, 2009
8,451
4,452
Pale blue comma
The only way to tell Terminal to make windows is with AppleScript.

That said, there is a shell command that will run AppleScript. It's called 'osascript'.
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/osascript.1.html


Since you didn't say what OS version you're using, you'll have to experiment with AppleScript. That's because different OS versions have different Terminal versions, and different Terminal versions have different scripting vocabularies. The following examples were tested on OS X 10.8.4. I don't know what other OS versions they'll work on.

Start by opening AppleScript Editor, then open Terminal's scripting dictionary. It's in the File menu, the Open Dictionary... menu-item. Refer to that as you read the following.

After some web-searching and experimenting, it seems the simplest way to tell Terminal to open a new window is this:
Code:
tell app "Terminal" to do script ""
Copy and paste that into AppleScript Editor, then run it. Terminal should open a new window. If you run it again, it should open another window.

Here's the 'osascript' equivalent of that one-liner:
Code:
osascript -e 'tell app "Terminal" to do script ""'
Copy and paste this one line into an existing Terminal window. A new Terminal window will open and come to front each time you paste it.

The result of do script is a reference to the new window. So run this script in AppleScript Editor:
Code:
tell application "Terminal"
	set _target to do script ""
	get name of (current settings of _target)
end
The first line stores the resulting reference in a variable named _target. The second line gets the name of that window's current settings set. To understand all the properties in a settings set, refer to Terminal's scripting dictionary, under the description for settings set.

Here's another script that lists all your settings sets:
Code:
tell application "Terminal"
	set _sets to every settings set
	repeat with _set in _sets
		set _name to name of _set
		log "name: " & _name
	end repeat
end
Look at the events & Replies in AppleScript Editor, so you can see everything listed.

For the next script, I first went into Terminal and made a new settings set in the Preferences window called "Big_Brew", which is a duplicate of "Homebrew" with a larger font. Do that BEFORE running the script, otherwise there won't be a settings set to apply. Then try this script:
Code:
tell application "Terminal"
	set _brew to first settings set whose name is "Big_Brew"
	tell front window to set current settings to _brew
end
The front window's appearance will change to "Big_Brew", showing that a new appearance can be applied to a window that's already open


Each of the above scripts illustrates one small part of the overall result you want to achieve. For example, I show how to open new windows, how to refer to a specific settings set, and how to apply a known settings set to a window. Now you get to experiment with AppleScript Editor and the 'osascript' command in Terminal, and build up smaller parts to make either an AppleScript app or a .command file that does what you want. If you're not interested in that process, then just use MacVIM. It needs less experimentation.
 
Last edited:

kryten2

macrumors 6502a
Mar 17, 2012
996
59
Belgium
Thanks chown33 for the write down. I know I was a little lazy when answering to the question from the OP but I wasn't entirely sure if he meant a .profile file or something else.

After some web-searching and experimenting, it seems the simplest way to tell Terminal to open a new window is this:
Code:
tell app "Terminal" to do script ""
This has been so since Leopard(could be Tiger) and we still have to jump through that hoop to make a new window. It would be so much easier if you could just do make new window or make new tab. Terminal could definitely use some TLC.

Lists all your settings sets:

Code:
tell application "Terminal" to get name of every settings set
 
Last edited: