Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Reset Terminal window environments via AppleScript System

I've been building a complicated, brittle system of shell scripts and AppleScript for switching all the little things that "Location Manager" doesn't handle (privoxy's forward settings, stunnel settings, etc.). This hint is about bash settings, and follows the familiar pattern of:


[ -f $HOME/.bash_profile.${LOCATION} ] && \
cp $HOME/.bash_profile.${LOCATION} $HOME/.bash_profile

This sets bash_profile up with my correct environment variables and aliases for each location. That 's fine for new Terminal windows, but what about all those Terminal windows that are already open? Lately I've been finding that what bash can't do, AppleScript can. After the bash_profile has been switched, I run:


tell application "Terminal"
  repeat with w in every window
    -- alt: do script ". $HOME/.bash_profile" in w
    if w is not busy then
      do script "exec bash --login" in w
    end if
  end repeat
end tell

This is a fairly powerful mechanism in general - you could check through the open windows for an idle one, and run a command on it. Look through Terminal's AppleScript dictionary - there's a lot of interesting functionality.

Note that this script seems to have bad interactions with osascript on 10.2.4: I had new windows popping up, for example. Running this AppleScript as a standalone script also avoids the other caveat: the window that you're running osascript in would not, itself, run your shell command. If that's a problem, you could just include the shell command directly in your script - or you could try running osascript in the background.

    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[10,728 views]  

Reset Terminal window environments via AppleScript | 3 comments | Create New Account
Click here to return to the 'Reset Terminal window environments via AppleScript' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Run custom scripts on location switch?
Authored by: awk on Fri, Mar 28 2003 at 12:47PM PST
Is it possible to run a custom script automatically whenever the location is changed in the GUI?

[ Reply to This | # ]
Reset Terminal window environments via AppleScript
Authored by: fotmasta on Fri, Mar 28 2003 at 5:52PM PST
Maybe I'm missing the point of this.
My Terminal "window settings" are not persistent. The checkbox for "use option key to position cursor." does not happen for each terminal I open.

[ Reply to This | # ]
AppleScript support for Terminal
Authored by: LouieNet on Sat, Mar 29 2003 at 3:54PM PST
mblakele wrote:
Look through Terminal's AppleScript dictionary - there's a lot of interesting functionality.
Just how functional is it all? The color stuff seems to only partially work.

Theoretically, this script below should make everything white for the top most window, but it doesn't. (No, I wouldn't normally want everthing the same color. I'm just illustrating the point that I think AppleScript support in Terminal is buggy.)

set testColor to "Snow"
tell window 1 of application "Terminal"
  set cursor color to testColor -- cursor color for the window
  set background color to testColor -- background color for the window
  set normal text color to testColor -- normal text color for the window
  set bold text color to testColor -- bold text color for the window
end tell
Does anyone want to verify my results?

--- Louie

---
G4 cube, 1152M RAM, OS X Server 10.2.4

[ Reply to This | # ]