Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Toggle terminal transparency via AppleScript Apps
Sure you can make the Terminal transparent by clicking command+i followed by clicking color, then moving the slider until the Terminal window is transparent ... but have you ever thought, hmmm, I wish that I could toggle the transparency on the Terminal with just the click of a button? Or, I would like to quickly see what is going on behind my Terminal window.

Well, here is a simple AppleScript that will do just that. You need to check the "Enable access for assistive devices" box on the Universal Access System Preferences panel in order to use the script. Assign the script a hot key in your favorite launcher, and toggle transparency until your heart is content. The script runs on Panther using tcsh; I am not able to verify it on Jaquar or future OSes or other shells.
tell application "Terminal" to activate
tell application "System Events"
  tell application process "Terminal"

    (* This just hit command i which opens the information preference pane *)
    key down command
    delay 1
    keystroke "i"
    key up command

    (* This will click on the popup button Color where the 
       slider transparency is located. *)
    delay 1
    click pop up button 1 of window "Terminal Inspector"
    delay 1
    click menu item "color" of menu "OtherViews" of pop up button 1 of 
     window "Terminal Inspector"
    delay 1
    get value of slider 1 of group 1 of window "Terminal Inspector"

    (* This toggles the transparency. You can set the transparency (95) and 
       opaque values (0) to anything you like. *)
    if value of slider 1 of group 1 of window "Terminal Inspector" is 0 then
      set value of slider 1 of group 1 of window 
       "Terminal Inspector" to 95 -- This is transparent
    else
      set value of slider 1 of group 1 of window 
       "Terminal Inspector" to 0 -- This is opaque
    end if

    (* This closes the preference pane window *)
    click button 1 of window "Terminal Inspector"

  end tell
end tell
Of course, you can do a lot of other things with this script like prompt for a dialog box and enter a slider value, or change background color, etc. This is just one example of how to access the feature rich preference pane box of Terminal that wouldn't otherwise be scriptable without a GUI scripting application. A fun thing to do with the script is to test it right from the hint. Simply select the code, click on services in the menu bar, select Script Editor, click on Run as AppleScript.
    •    
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[13,219 views]  

Toggle terminal transparency via AppleScript | 16 comments | Create New Account
Click here to return to the 'Toggle terminal transparency via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle terminal transparency via AppleScript
Authored by: LincolnQ on Aug 13, '04 10:54:31AM

This seems like a particularly klugey way of doing it -- simulating input?

I would like to believe there is a better way.

Also, you say that it runs under tcsh. What does tcsh have to do with it? This is not a shell script, it's an applescript.



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: roncross@cox.net on Aug 13, '04 12:36:12PM

What does tcsh have to do with it?

I just put that in the hint because when I open my
Terminal, it defaults to a tcsh. In other words, what I am saying is that I did not test it under any other shell, therefore, to be safe, I just put the conditions under which it works for me. If it works with other shell, then I am all the more delighted. The script just opens a terminal; and I guess it will work for any shell. Thanks for clarifying this for me.

Please feel free to find a better way of doing it. Notice, that I am not making a claim that this is the best way to do it. I believe that there is probably a better way, but my experience limits me to applescript at this time.

thx
RLC

---
rlc



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: GregChant on Aug 13, '04 12:55:26PM

I've come up with a better way:


tell application "Terminal"
	activate
	tell window 1
		if background color is "white" then
			set background color to {0, 0, 0, -25000}
			set normal text color to "white"
		else
			set background color to "white"
			set normal text color to "black"
		end if
	end tell
end tell

This code will toggle between Black on White and White on Transparent Black. The -25000 refers to the transparency level: set it lower to increase the transparency (changing it by the thousands seems to make the only difference).

Caveats/"Features": The normal text color doesn't update until you start typing, and the text and the title bar gain shadows.



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: roncross@cox.net on Aug 13, '04 11:25:53AM

The run as applescript command in services in the menu bar doesn't work anymore. When I submitted the hint, it did work, but I notice that the text looks difference now then when I submitted the hint. You will just have to copy the code into a script editor and give it a hotkey in your favorite launcher.

thx
RLC

---
rlc



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: nwfrg on Aug 13, '04 01:21:08PM
I don't use the tranparency option but I like to change the background color of Terminal. It helps me keep track of what server I'm working on when I have several Terminal windows open. I use a one line shell script to trigger a change:
osascript -e 'tell front window of app "Terminal" to set background color to {21331,1028,4369}'
I saved this as a shell script called "red" and I activate it from the comand line like this:
~/red

I would like to put it in my .tcshrc file as an alias but I've not been able to work around the quoting and escaping issues. I got the RGB color codes (21331,1028,4369) using Digital Color Meter.app which is in the utilities folder.

[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: dreness on Aug 14, '04 02:43:03PM

http://www.dreness.com/tips.html#bgcolor

In my case, the shell in question is zsh, but you can probably adapt it for the shell of your choice. If you have specific questions, it's probably best to email me, since I don't watch these forums that often.



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: markl2 on Aug 13, '04 07:54:51PM
Here is a somewhat improved version of the script:

local alpha
set alpha to 65
-- set between 0 (transparent) and 100 (opaque)

set alpha to (alpha * 65535) / 100

tell application "Terminal"
  local bg
  set bg to background color of window 1
  if number of items of bg = 4 then
    set bg to items 1 thru 3 of bg
  else
    set end of bg to alpha
  end if
  set background color of window 1 to bg
end tell


[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: Tim_Cox on Sep 02, '04 08:40:45AM

Has anyone actually had any success with this script? It seems to need some work...



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: roncross@cox.net on Aug 13, '04 11:39:09PM

Thanks, I learned something from this which is a good thing. The part that I was missing is that you can set the background to make the terminal transparent. I wasn't aware of this and I appreciate the feedback

thx
RLC

---
rlc



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: dclark1 on Aug 14, '04 10:39:23PM

For those of you who prefer to stay out of the terminal.
Download the haxie - "Window Shade" from Unsanity.
It does all of that and more for a small price.



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: RickoKid on Aug 15, '04 10:53:22PM
Or GeekBind which is not a haxie but a control panel. It can change transparency on ANY window! Very cool.

[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: roncross@cox.net on Aug 16, '04 09:39:02PM

I downloaded Geekbind and I like it so far. What is the difference between Window Shade and GeekBind? Both appear to have the ability to make windows transparent.

They both have other features as well.

thx
RLC

---
rlc



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: Silence on Aug 16, '04 02:23:06AM
I use iterm and use the following

tell application "iTerm"
	activate
	set current_terminal to (current terminal)
	tell current_terminal
		set current_session to (current session)
		tell current_session
			set old_transparency to transparency
			if old_transparency < "0.1"
				set transparency to "0.9"
			else
				set transparency to "0.05"
			end if
		end tell
	end tell
end tell
of for interactive setting

tell application "iTerm"
	activate
	set current_terminal to (current terminal)
	tell current_terminal
		set current_session to (current session)
		tell current_session
			set old_transparency to transparency
			display dialog "Set Transparency" default answer old_transparency  buttons {"Cancel", "OK"} default button 2
			set new_transparency to the text returned of the result
			set transparency to new_transparency
		end tell
	end tell
end tell


[ Reply to This | # ]
Toggle terminal colors for different servers
Authored by: davidswelt on Nov 19, '04 06:58:45AM

I use this to set the background color of terminal windows depending on the server that i'm logged on to in that window.

The previously posted code does this in AppleScript, but you'd need to have a way to trigger this depending on the server that's i'm SSH'ed into. I don't know how to do this, however, doing it via the shell automatically works just fine. Of course, we need to reset the color once the SSH session has ended, and for that, we need to remember the window ID that we're running in. Here's my SSH script that logs me into a server (via a proxy login server) that I've just written (you may need to check the line breaks):

[code]
#/bin/bash

THEW=`osascript -e 'front window of app "Terminal"'`
osascript -e "tell application \"Terminal\" to set background color of $THEW to {65535,38807,13621}"

ssh -t -X myusername@mydepartmentlogonserver.ac.uk 'ssh -X mymachine'

osascript -e "tell application \"Terminal\" to set background color of $THEW to {65535,59881,28013}"
[/code]

Get the colors with DigitalColor Meter as previously posted (thanks for the tip) -- set it to "RGB as Actual Value 16 Bit"

---
http://www.reitter-it-media.de // personal: http://www.davids-welt.de



[ Reply to This | # ]
Toggle terminal transparency via AppleScript
Authored by: davidswelt on Nov 22, '04 05:17:04AM
I use this to set the background color of terminal windows depending on the server that i'm logged on to in that window.

The previously posted code does this in AppleScript, but you'd need to have a way to trigger this depending on the server that's i'm SSH'ed into. I don't know how to do this, however, doing it via the shell automatically works just fine. Of course, we need to reset the color once the SSH session has ended, and for that, we need to remember the window ID that we're running in. Here's my SSH script that logs me into a server (via a proxy login server) that I've just written (you may need to check the line breaks):


#/bin/bash

THEW=`osascript -e 'front window of app "Terminal"'` 
osascript -e "tell application \"Terminal\" to set background color of $THEW to {65535,38807,13621}"

ssh -t -X myusername@mydepartmentlogonserver.ac.uk 'ssh -X mymachine'

osascript -e "tell application \"Terminal\" to set background color of $THEW to {65535,59881,28013}"
Get the colors with DigitalColor Meter as previously posted (thanks for the tip) -- set it to "RGB as Actual Value 16 Bit"

---
http://www.reitter-it-media.de // personal: http://www.davids-welt.de

[ Reply to This | # ]

Toggle terminal transparency via AppleScript
Authored by: lucianf on Nov 01, '07 01:56:58PM

Anyone knows how to address transparency in Leopard? Background color is RGB now, the 4th component is missing.



[ Reply to This | # ]