Some hidden features and other tips for OS/X...

This page is circa 2002. Some tips no longer valid. Also see: http://www.danrodney.com/mac/tipsandtricks.html A list of the top 10 tips for unix geeks: http://www.macdevcenter.com/pub/a/mac/2002/10/22/macforunix.html

Finder / terminal integration

Every finder or document window has a little icon (usually a folder) at the top, next to the the name of the folder. Initially I thought this was just a decoration. In fact it is a surrogate for the file for many operations. For example, drag the document icon for an open picture file onto photoshop to open the same file in photoshop.

Drag this icon into the terminal window and it expands into the path to that folder/file! This icon can also be dragged to a open/save-file dialog, causing the dialog to move to that directory, or dragged to a mail message, loading the file as an attachment, or dragged onto the photoshop app icon to cause photoshop to open it, etc. Apple-click on it to see the path to that document and navigate up the path.

In the terminal, "open ." causes the Finder to open a view of the current directory, and "open file.ext" will launch whatever application is used to open .ext by default. (The default appliation is set in the finder "get info" window).

  open -a app file
cause the file to be opened in a particular application (not sure how it knows where all the applications are - does anyone know?).

Alternately, applications can be launched unix-style from the commandline by running the actual executable that is located in Contents/MacOS. For example, /Developer/Applications/Utilities/FileMerge.app can be lauched as

   /Developer/Applications/Utilities/FileMerge.app/Contents/MacOS/FileMerge file1 file2

Go to a folder with cmd-shift-G, and the Finder->View->Customize Toolbar has a thing that can be dragged onto the toolbar to view the path hierarchy. It's the one that looks sort of like

-
 -  ^
  - 
(This can also be done by apple-clicking on the "small icon" as described above)

There is a script "open terminal here" on the web somewhere that gives a one-click open terminal (versus the trick above, which requires typing 'cd ' and then dragging the tiny folder icon). It can be added to the finder toolbar, see below.

ls | pbcopy
puts the output of ls (or some other command) into the copy buffer, then it can be pasted (cmd-V) into a gui application.

Extending the Finder

You can drag documents and applications to the Finder top bar. This means that you can add buttons that extend the behaviour of the Finder somewhat.

This link gives examples of adding a button to go to the parent directory -- not very useful, since there is a preprogrammed directory tree button in the 'customize toolbar' menu, as well as a pre-existing key shortcut, but it's a good example.

http://www.macosxhints.com/article.php?story=20070326144320146

Make an applescript, save it as an app, optionally choose a button icon and paste it onto the application, then drag it to the top bar.

Here's one person's example script from the link above:

tell application "Finder" to set p to target of window 1 as string

set x to POSIX path of file p
set z to do shell script "cd " & x & "; cd .. ; pwd"

tell application "Finder" to set target of window 1 to POSIX file z

Pdf, Latex, Keynote

You can drag&drop latex into Keynote, and even into margin notes of a .pdf!

latex

I use the mactex package, http://www.tug.org/~koch/
This page has a guide to latex on the mac and associated programs:
  http://guides.macrumors.com/Installing_LaTeX_on_a_Mac

latex in presentations

For doing equations in Powerpoint/Keynote, I've used the Latex Equation Editor, http://evolve.lse.ac.uk/software/EquationEditor ;
Equation Service (also latex based) is an alternate,
http://www.esm.psu.edu/mac-tex/EquationService/, as is Latexit,
http://ktd.club.fr/programmation/latexit_en.php

services

(Services are a neat OS/X feature - instead of implementing a spell check for every application, do a spelling "service" that can be accessed from any application.) Equation service allows latex math to be easily inserted into a mail message for example.

The OS/X display system is `display pdf'. This is useful in dealing with math typesetting:

drag & drop latex

Latex equations from Equation Editor (probably Equation Services as well) can be drag-dropped (or cut/pasted) into native applications (Keynote, textedit). In so doing the postscript is copied , not a bitmap! In keynote one can then resize the equation arbitrarily, as well as rotate, add drop shadows, and other things that can be done with outline fonts. A web page with more detail is http://darkwing.uoregon.edu/~noeckel/Keynote.html

math scrapbook

This also gives a nice way to keep a notebook that involves math:
Rect-select regions of any .pdf (including math, or figures), and then paste into either Keynote or perhaps TextEdit.

latex in the margins of a .pdf

For a long time I've wanted to be able to add math margin notes to a pdf. With OS/X's pdf-based display this seemed like it should be possible, but Acrobat doesn't do it -- it cannot accept pdfs that are drag/dropped or pasted. I was even considering writing some tool to do it, but just found the way:

combination of latex equation editor (free, great with keynote) and "PDFpen"

PDFpen is an acrobat (full, not reader) -like program that's written using the modern mac libraries; it's possibly worth it just as an acrobat alternative. Not free, $50 from http://www.smileonmymac.com

With these two programs, you can type latex into Latex Equation Editor, then drag-and-drop the resulting mini pdf onto the pdf in PDFpen, resize it there, and save.

One caveat is that PDFpen has to be in pointer mode or have most recently used the insert-image-or-pdf button; if it's in scribble or other annotation mode it does not accept the drop.

keynote vs. Powerpoint

Keynote is apple's alternative to Powerpoint, and I definitely prefer it. The main reason is simply that it looks better (good kerning and font antialiasing). There are also some subtle things that help with alignment, and a nice double-screen feature that shows the speaker a timer and a preview of the upcoming slide... and flashy opengl transitions. On the downside there is not much support for drawing; I most often use Omnigraffle for this.

Vector illustrations

Omnigraffle is an illustrator-like program, but with an unusual interface - better "intelligence" for placing stuff. It produces beautiful output. Another alternative is Inkscape -- great X11 .eps/.svg editor, more similar to illustrator, but with a somewhat more logical interface in my opinion.

djvu

A djvu viewer is at http://www.lizardtech.com/download/

Key shortcuts

http://www.danrodney.com/mac/index.html

The text entry widget has emacs key bindings enabled by default, so for example you can edit the middle of a url or text in a dialog box without having to switch to the mouse and back. This is particularly nice for composing emails. I've seen it work in Safari, Finder, TextEdit, etc.

Key shortcuts can be changed or added in several ways-

  • A basic set is configurable under the keyboard&mouse control panel, the existing ones can be changed, and

  • you can add new ones for any menu in any program (*) by htting the "+" key. (Also note the "turn on full keyboard access here")

  • More exciting, The file ~/Library/KeyBindings/DefaultKeyBinding.dict can define shortcuts for things other than menus, e.g. moving in a file-save box or in the web url. This is something my fingers now cannot live without... Here's a set that allows emacs-style editing:
    {
            "~f"="moveWordForward:";
            "~b"="moveWordBackward:";
            "~<"="moveToBeginningOfDocument:";
            "~>"="moveToEndOfDocument:";
            "~v"="pageUp:";
            "~d"="deleteWordForward:";
            "~^h"="deleteWordBackward:";
            "~\010"="deleteWordBackward:"; /* Alt-backspace */
            "~\177"="deleteWordBackward:"; /* Alt-delete */
    
            /* Escape should really be complete. */
            "\033"="complete:"; /* Escape */
    } 
    
  • for really weird stuff, you can actually alter the interfaces of existing programs either by editing xml, or (easier) by editing them in the interface builder program. This could be used to change menu names/window sizes, or add key shortcuts that live inside the program rather than being applied to the outside.

    There is a property list editor in /Developer/Application/Utilities.

    (More about this, copied from macosxhints or someplace:

    There seem to be a lot of rules about what keys combinations you can and
    cannot edit in the Keyboard preference pane. Apple has definitely forbidden
    the creation of simple command-key shortcuts, for instance. Also, there are
    other limitations out there about replacing existing shortcuts as well.
    
    There is a simple way around these limitations however. Open up the file
    ~/Library -> Preferences -> .GlobalPreferences.plist with Property List
    Editor. Fnd and open up the NSUserKeyEquivalents key. Edit away as many
    keyboard shorcuts as you like.  These are the code for special characters in
    the plist file:
    	 	Command is @
    	 	 Shift is $
    	 	 Control is ^
    	 	 Option is ~
     There's no need to work on each application's own plist files; all menus are
     fixable in globalpreferences.plist (I had some trouble with Adobe
     applications, though). Don't forget to quit and relaunch applications to see
     their new keyboard commands show up (visible in the menu).
    
    To add/change a keyboard shortcut:
    Install the Developer Tools. Find Interface Builder - that's your new
    ResEdit. Then locate the appropriate .nib file in the application to be
    modified's package (cntrl-click the app and show package contents). It will
    be in Contents/Resources, and could be named MainMenu.nib or something. Once
    you've got it open in Interface Builder, it is pretty easy to navigate the
    menu, find your entry, get info on it and change the shortcut. Be careful
    not to set it to anything already in use, including System shortcuts such as
    Cmd-H or Cmd-M.
    
    )

    (*) Altering programs only works for programs that are compiled using the OSX api... not everything is; for example Photoshop 8 and the Microsoft apps are not.

cmd-ctrl-shift-3 copies to clipboard
cmd-ctrl-shift-4 copies a rectangle select to clipboard

Video

Quicktime does not open all movie types, but accepts plugins or drivers for some additional movie types. There is a divx driver/plugin? I once found on the web.

Mplayer and videolan - usually a movie can be opened in one of thes if Quicktime doesn't open it. Mplayer is at http://www.versiontracker.com/dyn/moreinfo/macosx/27163 , videolan at www.videolan.org/vlc

Free iSquirt app can convert from flash and other video formats. (Flash videos can be saved using the video downloader firefox plugin).

The intel macbook did not come with flash preinstalled (probably too new). There is a beta now http://www.adobe.com/products/flashplayer/public_beta/

skype version with video, Aug06 beta: http://www.skype.com/download/skype/macosx/videopreview.html

Microsoft had a Mac video player that was horrible; they discontinued it in favor of a third-party player "Flip4mac".

  http://www.flip4mac.com/
   http://www.microsoft.com/windows/windowsmedia/player/wmcomponents.mspx
   http://www.microsoft.com/downloads/details.aspx?FamilyId=915D874D-D747-4180-A400-5F06B1B5E559&displaylang=en

Perian is a "a free, open source QuickTime component that adds native support for many popular video formats". http://perian.org/

File Types

The .ext -> application mapping is set by doing "Get Info" on a file in the Finder. It can be set for the particular file or for all files of that type.

Admin account

I follow a unix-like practice of using two accounts, an "admin" account for installing software, and a second non-admin account for regular use.

macports, fink, X11

X11 is on the bundled dvd but is an optional install. Macports (formerly Darwinports) and fink are two systems that package unix utilities for easy installation. I have used both... Both install everything into parallel directories (/sw for fink, /opt for darwinports) so they do not depend on or interfere with the OS/X unix libs. Fink: it works, but I found the documentation for Fink to be incomprehensible. http://fink.sourceforge.net/ Macports is easy to understand, but does not have a binary install option (everything is compiled from source, so the first time you install something, it will spend probably an hour or two pulling and compiling dependencies. macports.org

Resource Forks

Beware that some files (typically older applications) have "resource forks" (a form of metadat from the original mac file system).

Using unix "cp" may not be enough to copy such files. Use "ditto -rsrcFork src target" instead, e.g.

ditto -rsrcFork /Applications /Volumes/Backup/Applications

To copy stuff to an archive and later restore,

  ditto -c -z -v -V -X dir file.cpio    # save dir in file.cpio
then
  ditto -x file.cpio dir                # extract

This page has a discussion (Actually there is more to it than I realized): http://developer.apple.com/macosx/backuponmacosx.html

Other

from James Hopper in the OpenSceneGraph documentation: "You can set environement variables that work with applications by creating a file ~/.MacOSX/environment.plist and put them in there", or use the preference pane called RCEnvironment at http://www.rubicode.com/Software/RCEnvironment/

Selecting by word: double click, but hold the second click. Then dragging the mouse expands the selection by words rather than characters.

To make a copy of a CD or dvd, one way is to use

Utilities->Disk Utility
  New image from device
    ** set the two options Uncompressed and CD/DVD master
    (save, it writes a *.cdr or *.dmg file)
the resulting .cdr file can be burned multiple times.

The spotlight search is useful, but if you're already sitting in a terminal window the unix "locate" command is good too. (The locate database only gets updated once a month at 4am or something).

  open `locate xx.doc`
to find and open a word doc in one step.

Send a pop-up message to someone on a windows machine:

  echo "message text" | smbclient -M NETBIOSNAME -u fromname

Send message from ichat to phone:

  File->New Chat With Person, enter +1310xxxyyyy or whatever,
  brings up a chat window, then under buddies 
  it will have add +1310xxxyyyy as buddy, do this.

Convert property list to xml format: plutil -convert xml1 com.apple.mail.plist

/Developer/Applications/Utilities/FileMerge.app - a visual diff tool

The ongoing wine port to windows (run windows apps under OSX): http://sourceforge.net/projects/darwine/

Create, list, Unpack a .zip file from the terminal

   jar cvf file.zip files...
(syntax similar to tar).

http://www.macosxhints.com is a good website for additional tips.

Quick dictionary lookup: mouse over the word, then apple+ctrl+d brings up a dictionary popup. Probably does not work in microsoft apps.

Find out what process is keeping a mounted volume open (or the trash from being emptied)

  lsof | grep "/Volumes/VolumeName"
  lsof | grep 

Setting an environment variable for a gui application: One way to do this is to create a directory ~/.MacOSX and create a file environment.plist in this directory, containing the env variables in plist format. The 3Delight renderer does this. You need to logout and back in to get it. Alternately, set the env var in a regular shell and "open X.app".

How to copy a program

Most of the time simply copying the application (or the folder it is in) will work. Sometimes the install puts supporting information in these places: /Library/Application Support/ e.g. /Library/Application Support/Adobe Systems and [home]/Library/Application Support/ .... The first of these is the library folder for the entire system, the second one is for your individual user. Rarely, there can be a folder inside /Library or [home]/Library but outside of the Application Support subfolder. Copy these various folders and the program may work. A debugging technique, open a Terminal window, then run the command "lsof | grep Photoshop" while the program is starting up (substitute the particular program for "Photoshop". Lsof is "list-open-files", it shows all files that are open, which can help uncover any other scattered files.