0

When a user loads my C++ program, I want Terminal to look a certain way. I solved this by wrapping my program in an AppleScript .app which overwrites ~/Library/Preferences/com.apple.Terminal.plist (making a backup first) before opening the program. With a subsequent killall cfprefsd, this works (if Terminal wasn't open to begin with!), but I don't want to mess up the user's own Terminal preferences. So, after calling my program I overwrite ...Terminal.plist again with the backup of the original settings.

The problem is that when my program is done and Terminal closes, its preferences are automatically overwritten with that of the current window, meaning the user is stuck with the look I set for my program. I tried to counter this by having the AppleScript wait until Terminal was closed and then overwriting the plist with the backup once more, which works, but if my app were to be closed before Terminal then this fails of course. And the whole process seems pretty hacky to begin with.

Can I prevent Terminal from overwriting its preferences when it closes? Or even better, can I have my code run in a terminal that looks the way I want without messing with the user's settings? Preferably I wouldn't use Terminal at all to run my code (so it also doesn't fail when Terminal was already open), but I think the only alternative is writing my own...

  • 1
    Why are you using the terminal instead of running the needed unix command directly to macOS? In applescript you use do shell script. You could use iterm2 instead. – historystamp Jun 13 at 18:17
  • The AppleScript serves as a wrapper for my executable, which displays stuff on a terminal window. So since I had the wrapper there anyway, it made sense to me to use it to set up Terminal before launching the program itself. I tried iterm2 but could not get it to work like I was hoping either. – CosmoM Jun 13 at 18:55
  • What happens to other uses of the terminal do they work with your settings? If you need so much control write a gui app – Mark Jun 13 at 23:06
1

I'd look into what can be done with applescript using the scripting dictionary.

script editor > file > open scripting dictionary

I do not know the details of what you are doing but here are some coloring options.

enter image description here

  • Thanks! From what I can tell, FISH still uses Terminal on MacOS though. But changing the look of the Terminal through AppleScript is a good idea, I didn't know that was possible. – CosmoM Jun 13 at 18:52
  • I'll delete the stuff on FISH. You are correct, "fish.app bundles the fish shell with an AppleScript that launches it in Terminal. Nothing is installed." – historystamp Jun 13 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .