Sunday, April 26, 2009

Lock the screen and turn off iMac display

Here's how I got my iMac to (effectively) lock the screen and sleep the display:
  1. Get Spark (for the keyboard shortcut)
  2. Get SleepDisplay (to sleep the display)
  3. Check "Require password to wake this computer from sleep or screen saver" in System Preferences->Security->General
  4. Create a new AppleScript Action in Spark with the following code:
do shell script "/Applications/SleepDisplay.app/Contents/MacOS/sleepdisplay"
do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -module 'Computer Name'"

If you don't need to sleep the iMac display (have an external monitor with a power button), you can do this:
  1. Check "Enable fast user switching" in System Preferences->Accounts->Login Options
# This brings up "switch users", but doesn't keep the display killed
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"

"Friendly" terminal placement with applescript

A lot of my work flow involves opening new terminals. Unfortunately, OS X almost always puts its new terminals right on top of its old ones, which is not terribly useful to me. With a bit of Applescript (launched by Spark), I make them launch to the side of the current (active) window. It's a good start, at least.


# Get topmost app
tell application "System Events" to set frntProc to name of every process whose frontmost is true and visible is true
tell application named (item 1 of frntProc) to set currBounds to the bounds of the front window

# Get desktop bounds
tell application "Finder" to set desk to the bounds of the window of the desktop

tell application "Terminal"
activate (do script with command "")

set newBounds to the bounds of the front window

# Get the distances we're working with
set onLeft to (item 1 of currBounds)
set onTop to (item 2 of currBounds)
set onRight to ((item 3 of desk) - (item 3 of currBounds))
set onBottom to ((item 4 of desk) - (item 4 of currBounds))

set newW to ((item 3 of newBounds) - (item 1 of newBounds))
set newH to ((item 4 of newBounds) - (item 2 of newBounds))

if (onRight > newW) then
set the bounds of the front window to {item 3 of currBounds, (item 2 of currBounds) + newH, (item 3 of currBounds) + newW, (item 2 of currBounds) + newH * 2}
else if (onBottom > newH) then
set the bounds of the front window to {item 1 of currBounds, (item 4 of currBounds) + newH, (item 1 of currBounds) + newW, (item 4 of currBounds) + newH * 2}
else if (onLeft > newW) then
set the bounds of the front window to {(item 1 of currBounds) - newW, (item 2 of currBounds) + newH, item 1 of currBounds, (item 2 of currBounds) + newH * 2}
else if (onTop > newH) then
set the bounds of the front window to {item 1 of currBounds, item 2 of currBounds, (item 1 of currBounds) + newW, (item 2 of currBounds) + newH}
end if

end tell

Sunday, April 19, 2009

Launch X apps remotely through ssh

Launch my_X_prog remotely over ssh:
env DISPLAY=:0 ./my_X_prog

Friday, April 17, 2009

for loop with numbers in bash

Lately, I was trying to download back issues of web comics. Bash supports for loops with numbers, but I needed leading zeros. Apparently the seq command can do this. Here's the loop I used:

for i in $(seq --format="%02.f" 1 17); do
echo "wget http://archive.leasticoulddo.com/strips/200904$i.gif";
done

Sunday, April 5, 2009

Several tables side by side (without nesting)

This page shows a technique for putting several tables side by side, and explains some compatibility issues.

Here's the style ([] for posting...should be <>):
[code]
[style type="text/css"]
table{vertical-align:top}
table.inline{display:inline-table}
.inline{display:inline}
[/style]
[/code]

...and how you use it (same deal with []):
[code][table class='inline'][tr][td]blah blah blah...[/td][/tr][/table][/code]

Friday, April 3, 2009

Prevent new fvwm windows from covering gnome panel

You can tell fvwm to put windows where they will cover as few existing pixels as possible with:
Style * MinOverlapPlacement

I like to use fvwm as my wm for gnome. To make the gnome panel act more like it does in gnome:
Style "*panel" NotTitle, !Borders, NoHandles, Icon, Sticky, WindowListSkip, CirculateSkip
(this may be overkill, but it works for me)

To prevent auto-placed windows from covering the gnome panel (or similar windows marked as Icon or with EWMH Struts enabled):
Style * MinOverlapPlacementPenalties 1 5 9999999 1 0.05 9999999
Note: the small values are based on the defaults, according to the man page. The large number was chosen to be larger than any (sane) resolution you might use (ie: 1600x1200=1920000 or 2*1280x1024=2621440). This obsene penalty for Icon or Struts windows ensures they won't be covered by new windows.