![]() |
![]() |
Instructions: The scripts and code on this page can be cut and pasted directly into either the Terminal or the Script Editor, saving you the trouble of typing them out yourself. You'll find a few of these code snippets are quite wide. They were entered this way on purpose, so as to not introduce any extra line breaks. Here's how to read the various bits of code you'll see on this page...
Commands you type directly into the terminal are shown in monospace green on black text. If the line is an actual Unix command, it's shown with a leading $ symbol to indicate the command prompt:
| $ some terminal command/goes here > example.txt $ some other terminal/command /goes > here.txt |
Do not copy the $ sign, nor the space shown immediately next to it; select all the text beginning with the first character after the space. If there is more than one command, each occurrence of the $ sign indicates a new line, and each line should be copied and pasted one at a time. Scripts that are to be entered in a UNIX text editor, such as vi, pico, or emacs, along with commands to set various preferences, are shown in the same monospace green on black text, but lack the leading $ sign:
| #!bin/bash # some script first line of script example next line of script example |
In these cases, simply copy and paste the entire block or line into the text editor of your choice (or Terminal, if it's a preferences command). Finally, AppleScripts are shown in gold with a sidebar set-off, and can be copied and pasted directly into Script Editor in one step:
tell application "some_app" do something set some_var to 21 end tell
Use the following navigation table to jump directly to the specified (chapter number - hint number) hint:
| Chapter 1 |
Chapter 5
Chapter 6
Chapter 7
Chapter 9
Chapter 10
|
Chapter 11 | Chapter 14 |
Chapter One
Hint 1-17: Double Arrows on Both Ends
To place a double-scroll arrow at each end of the scrollbar:
defaults write "Apple Global Domain" AppleScrollBarVariant DoubleBoth
Chapter Two
To remove the zoom rectangles when opening applications:
defaults write com.apple.finder ZoomRects -bool noTo restore the zoom rectangle effect:
defaults write com.apple.finder ZoomRects -bool yes2-19 A Quit Menu in the Finder
Add a Quit menu to the Finder:
defaults write com.apple.finder QuitMenuItem -bool yesTo show all hidden files in the Finder:
defaults write com.apple.finder AppleShowAllFiles -bool yesTo hide all hidden files in the Finder:
defaults write com.apple.finder AppleShowAllFiles -bool no2-53 A Folder Action Script to Organize the Desktop
A script to move image files from your Desktop to a new "Unfiled" folder in your pictures folder. Paste the following in Script Editor, or just click here to let AppleScript do the work for you.
on adding folder items to this_folder after receiving added_items
tell application "Finder"
set homeFolder to (container of (path to desktop folder) as string)
set folderLocation to homeFolder & "Pictures:Unfiled:"
repeat with aFile in added_items
if the name extension of aFile is in {"jpg", "gif", "png", "pict", "tiff", "gif", "psd", "bmp"} then
tell application "Finder"
try
move aFile to folder folderLocation
display dialog Â
"Image files have been moved to the Unfiled" & return & "folder in your Pictures folder."
on error err
display dialog err
end try
end tell
end if
end repeat
end tel
end adding folder items to
2-54 Open the Finder Selection in the Terminal
Copy and paste the following into Script Editor, or just click here to have AppleScript do the work for you:
(*
Open in Terminal
Copyright 2002 Gregory Ramsperger
*)
property badPathChars : {"\\", "`", "!", "$", "&", "(", ")", "{", "}", "|", "'", "\"", ";", "<", ">", "?", " "}
-- drag-and-drop open
on open theList
set dir to (item 1 of theList) as text
my oit(dir)
end open
-- direct run
on run
try
tell application "Finder"
set dir to the target of Finder window 1 as text
end tell
my oit(dir)
on error
my oit(path to desktop)
end try
end run
-- run a command in the terminal
on oit(d)
tell application "Finder"
if d does not end with ":" then
set d to (container of item d) as text
end if
end tell
set p to (POSIX path of d)
repeat with c in badPathChars
set AppleScript's text item delimiters to c
set tempitemList to every text item of p
set AppleScript's text item delimiters to ("\\" & c)
set p to the tempitemList as string
set AppleScript's text item delimiters to ""
end repeat
tell application "Terminal"
activate
do script with command ("cd " & p)
end tell
end oit
2-60 Screen Saver as the Finder Background
To run the currently selected screensaver as the desktop background:
$ /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background
Chapter Three
Unless otherwise noted, you must restart the dock in order to see the effects of any of the following changes.
To put the dock at the top of the screen, open the Terminal and type:
defaults write com.apple.Dock orientation -string top3-7 Changing the Minimize Action
To use an undocumented "suck in" action for the minimize effect:
defaults write com.apple.Dock mineffect suck3-8 Pinning the Dock to a Corner
To place the dock at the far right (bottom if vertical) of the screen:
defaults write com.apple.Dock pinning endTo place the dock at the far left (top if vertical) of the screen:
defaults write com.apple.Dock pinning startTo place the dock back in the middle of the screen:
defaults write com.apple.Dock pinning middle3-9 Differentiating Hidden Programs
To show hidden programs with a transparent icon:
defaults write com.apple.Dock showhidden -bool yesTo remove hidden programs' transparent icons (dock must be restarted to see the change):
defaults write com.apple.Dock showhidden -bool no3-17 An AppleScript to Restart the Dock
Paste the following lines in the Script Editor application in the /Applications -> AppleScript folder:
tell application "Dock" quit end tell
Save the script as an Application and check the "Never Show Startup Screen" box to make it easy to use (a simple double-click will restart the dock).
To permanently get rid of the dock (takes effect on next login):
|
$ cd /System/Library/CoreServices $ sudo mv Dock.app ~/Documents/Dock.app |
To restore the dock (takes effect on next login):
| $ cd /System/Library/CoreServices $ sudo mv ~/Documents/Dock.app /System/Library/CoreServicesDock.app |

Chapter FOUR
4-8 Fun with the Floating Desktop Blob
To enable a strange, floating blue blob that activates Exposé, type this in the Terminal:
defaults write com.apple.dock wvous-floater -bool trueTo disable it again, repeat the above with false instead of true.
4-9 Change Exposé's Show Desktop Behavior
To shrink all windows into a tiny desktop icon when you hit F9, type this in the Terminal:
defaults write com.apple.dock wvous-olddesktop -bool falseTo return to the normal Exposé mode, repeat the above with true instead of false. Warning: This hack has been known to cause some system stability issues, and the small window created is a "dead zone" for any mouse clicks -- even when the window isn't in use!
4-24 Speed Up the Display of Sheets
This command will change the sheet draw speed to super-fast:
defaults write NSGlobalDomain NSWindowResizeTime 0.001To revert to normal, type:
defaults delete NSGlobalDomain NSWindowResizeTime
Chapter FIVE
5-9 Renaming the System Preference Categories
Step #1:
|
$ cd "/Applications/System Preferences.app/Contents/Resources/English.lproj" $ sudo cp NSPrefPaneGroups.strings NSPrefPaneGroups.bak $ sudo cp NSPrefPaneGroups.strings ~/Desktop/MyPrefs.strings |
Step #5:
$ sudo cp ~/Desktop/MyPrefs.strings NSPrefPaneGroups.stringsStep #6 (restores backup if you're having problems):
| javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('Keywords...',''))};if(Qr)location.href='http://google.com/search?query='+escape(Qr)+'&num=20' |
There is no line break or added space -- just copy and paste as one long line.
12-57 Emailing URLs from Safari
The content of the special bookmark is:
javascript:location.href='mailto:?SUBJECT='+document.title+'&BODY='+escape(location.href)12-58 Add the Missing Print Button
The content of the special bookmark is:
javascript:window.print( )12-59 Create Custom Clicked-Link Outlines
The content of the text file is:
:link:active, :visited:active { outline: 3px auto; }Type the following in the Terminal:
defaults write com.apple.Safari IncludeDebugMenu Ðbool true
Chapter THIRTEEN
The following two hints both relate to DragThing. Enter each script in Script Editor, or click the associated link, and run them as explained in the book.
Enter into Script Editor, or just click here and let AppleScript do the work:
tell application "DragThing" set shouldFade to do not use fading set do not use fading to (not shouldFade) end tell
Enter into Script Editor, or just click here and let AppleScript do the work:
tell application "DragThing" set useBadge to do not use running app badge set do not use running app badge to (not useBadge) end tell

Chapter FOURTEEN
Type the following command in the Terminal to replace the Finder with Path Finder:
defaults write com.apple.loginwindow Finder /Applications/Path\ Finder.appTo return to the standard Finder:
defaults delete com.apple.loginwindow Finder
Chapter FIFTEEN
15-24 Open a New Terminal Window in the Current Directory
Create the following script in your favorite Unix text editor:
| #!/bin/sh osascript<<END tell app "Terminal" do script "cd \"`pwd`\"" end tell |
Step #1:
| $ cd /System/Library/CoreServices/Dock.app $ cd Contents/Resources/English.lproj $ sudo cp InfoPlist.strings InfoPlist.bak $ sudo cp InfoPlist.strings ~/Desktop/InfoPlist.txt |
Step #5:
| $ sudo cp ~/Desktop/InfoPlist.txt InfoPlist.strings $ sudo chown root:wheel InfoPlist.strings |

Chapter SIXTEEN
16-6 Hiding an Application from the Command Line
Create the following script in your favorite Unix text editor:
| #! /bin/sh # hide an application in the Finder osascript <<END tell application "Finder" if exists application process "$1" then set visible of application process "$1" to false end if end tell |
16-8 Fast User Switching from the Command Line
Enter the following into Script Editor, or just click here and let AppleScript do the work:
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
16-17 Finding Files in the Current Directory Tree
Finding duplicate files:
| $ find . -size 20 \! -type d -exec cksum {} \; | sort | tee /tmp/f.tmp | cut -f 1,2 -d ' ' | uniq -d | grep -hif - /tmp/f.tmp > ~/Desktop/duplicates.txt |
16-24 Customizing Your Shell Prompt
A sample bash shell prompt:
| $ PS1='\[\033[43;34m\][\h:\w] \u\$ \[\033[0m\]' |
16-25 Removing Space from File Names
| #! /bin/sh for n in * do OldName=$n NewName=`echo $n | tr -d " "` #NewName=`echo $n | tr -s " " "_"` echo $NewName mv "$OldName" "$NewName" done |
16-37 Port Scans from the Terminal
| $ sudo ln -s "/Applications/Utilities/Network Utility.app/Contents/Resources/ stroke" /usr/local/bin/portscan |
16-40 Jazzing Up Your Site: Server-Side Includes
This is the script from step 12 in the instructions:
|
<HTML> <HEAD> <TITLE>My SSI Test Page</TITLE> </HEAD> <BODY> <b>Today is:</b><br> <!--#echo var="DATE_LOCAL"--> </BODY> </HTML> |
16-43 A Windows-Sharing Management Tool: SWAT
Step 2: /etc/xinetd.d swat file:
| service swat { port = 901 socket_type = stream wait = no only_from = localhost groups = yes user = root server = /usr/sbin/swat log_on_failure += USERID disable = No } |
16-44 Apache’s Server Statistics
Step 4:
| $ sudo cp webalizer /usr/local/bin/webalizer $ sudo chmod 755 /usr/local/bin/webalizer $ sudo cp webalizer.1 /usr/local/share/man/man1/webalizer.1 $ rehash |