Tag Archive for osx

Show OS version from command line (Mac)

sw_vers

source

Clear OSX Leopard DNS cache

$ dscacheutil -flushcache

source

Recursively list all files and directories below a given directory

/*
 This is example code of how to walk a directory recurisively
 and create a flat list of fully qualified names for all the files
 and directories under the supplied virtual root directory.
 */

#import <CoreServices/CoreServices.h>
#import <AppKit/AppKit.h>
#import <stdarg.h>

int main (int argc, const char * argv[])
{
    int result = EXIT_SUCCESS;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
    NSString *dir = [args stringForKey:@"file"];
    NSMutableSet *contents = [[[NSMutableSet alloc] init] autorelease];
    NSFileManager *fm = [NSFileManager defaultManager];
    BOOL isDir;
    if (dir && ([fm fileExistsAtPath:dir isDirectory:&isDir] && isDir))
    {
        if (![dir hasSuffix:@"/"]) 
        {
            dir = [dir stringByAppendingString:@"/"];
        }

        // this walks the |dir| recurisively and adds the paths to the |contents| set
        NSDirectoryEnumerator *de = [fm enumeratorAtPath:dir];
        NSString *f;
        NSString *fqn;
        while ((f = [de nextObject]))
        {
            // make the filename |f| a fully qualifed filename
            fqn = [dir stringByAppendingString:f];
            if ([fm fileExistsAtPath:fqn isDirectory:&isDir] && isDir)
            {
                // append a / to the end of all directory entries
                fqn = [fqn stringByAppendingString:@"/"];
            }
            [contents addObject:fqn];
        }
        
        NSString *fn;
        // here we sort the |contents| before we display them
        for ( fn in [[contents allObjects] sortedArrayUsingSelector:@selector(compare:)] )
        {
            printf("%s
",[fn UTF8String]);
        }
    }
    else
    {
        printf("%s must be directory and must exist
", [dir UTF8String]);
        result = EXIT_FAILURE;
    }
    
    [pool release];
    return result;
}

source

rm -i `plutil -s *.plist | grep 'plist:' | sed 's/://g'`

source

Install htop on OSX Leopard

git clone <a href="git://github.com/AndyA/htop-osx.git" >git://github.com/AndyA/htop-osx.git</a>
cd htop
git checkout -b osx origin/osx
./autogen.sh
./configure
make
sudo make install

source

Terminal – Turn On or Off Hidden Files

#Turn On Hidden Files in Terminal  - - - - -

defaults write com.apple.finder AppleShowAllFiles -bool true

#Turn Off Hidden Files in Terminal  - - - - -

defaults write com.apple.finder AppleShowAllFiles -bool false

source

OSX – enable disable spotlight indexing

// disable spotlight indexing

sudo mdutil -i off

// enable spotlight indexing

sudo mdutil -i on

// delete existing spotlight indexes
sudo mdutil -E

// some other options:  -s = display status, -v = verbose

source

Open a manpage in Preview.app

# Open a manpage in Preview, which can be saved to PDF
pman()
{
man -t "${1}" | open -f -a /Applications/Preview.app
}

source

Automated Screen-Capture

while [ 1 ]; do
/usr/sbin/screencapture -T0 ~/Desktop/screen-`date +%F-%H-%M-%S`.png
sleep 15
done

source

OSX Keyboard Shortcuts

Screen Capture to disk:

⌘ ⇧ 3                   Screen to jpeg file on desktop
⌘ ⇧ 4 + Drag:           Selection to jpeg file on desktop
⌘ ⇧ 4 + Spacebar:       Window (click camera) to jpeg file
Screen Capture to clipboard:

⌘ ⇧ 3 + Ctrl:           Screen to clipboard
⌘ ⇧ 4 + Drag + Ctrl:    Selection to clipboard
⌘ ⇧ 4 + Spacebar + Ctrl Window (Camera effect)
Dock /Switch Applications

⌘ ⌥ D      Show/Hide Dock
⌘ Tab      Switch applications
⌘ `        Switch between document Windows in current application
⌥ Dock     Switch application, hide previous one
⌘ Dock     Switch application, hide all others
Ctrl ⌥ ⌘ *  Toggle Monochrome Hi Visibility
⌘ +drag will prevent dock icons from moving out of the way
(useful for when dragging stuff to trash)
Apple Finder

⌥ + Drag   Explicit COPY (will copy even if destation is on same volume)
⌘ + Drag   Explicit MOVE (will move even if destation is on different volume)
⌘ ⌥ + Drag Make alias in new location
⌘ D        Duplicate
⌘ L        Make Alias
⌘ R        Show original
⌘ O        Open item
⌘ ↓        Open item
⌘ S        Save
⌘ ⇧ S      Save as
⌘ N        New Finder window
⌘ ⇧ N      New Folder
⌘ Q        Close Application
⌘ W        Close Window
⌘ ⌥ W      Close all Windows
⌘ I        Get Info
⌘ ⌥ I      Super Get Info (change whatever you click on)
⌘ P        Print
⌘ T        Add to Favorites
⌘ Delete   Move to Trash
⌘ E        Eject
⌘ F        Find
⌘ ~        Cycle finder windows (including desktop)
Tab        Highlight next item
⌘ + double-click folder icon will open in new window
⌘ + ↑      Move up one directory
⌘ + [      go back
⌘ + ]      go forward
⌘ ⇧ A     Open Applications Folder
⌘ ⇧ U     Open Applications/Utilities/ Folder
⌘ ⇧ H     Open Home Folder
⌘ ⇧ K     Go to network
⌘ K        Connect to server
⌘ ⇧ G     Go to folder... (type full path)
⌘ ⇧ ⌫     Empty Trash (Finder Menu )
⌘ ⇧ ⌥ ⌫   Empty Trash without dialog

Finder-Hide App:
⌘ H        Hide Finder
⌘ ⌥ H      Hide Others

Hide all other apps*:
⌥ ⌘ + click on dock icon
⌥ ⌘ + click inside app window

Hide all other apps that are in front*:
⌥ + click dock icon (of running app)
⌥ + click inside app window

*Some older (pre-intel) apps may struggle with these
Terminal

⌘ left/right arrow   Switch windows
⌘ 1                  Switch to 1st terminal window
⌘ 2, ⌘ 3...          Switch to 2nd, 3rd window
Editing Text (email, TextEdit etc)

⌥ ←       Move one word left
⌥ →       Move one word right
⌘ ←       Beginning of line
⌘ →       End of line
Scroll one page up (cursor retains position)
Scroll one page down (cursor retains position)
⌥         Move one page up  (reposition cursor)
⌥         Move one page down
⌘ ↑ or   Scroll to beginning of document
⌘ ↓ or   Scroll to end of document

Add shift key ⇧ to the above to also SELECT the text.

⌥ ⌫       Delete word
⌥ Del     Delete next word

⌥ Scrollbar           Jump to exact scrollbar location
⌥ Scrollbar arrows    Scroll page at a time (page up/down)
⌥ Volume up/down      Open Sound preferences
⌥ Brightness up/down  Open Display preferences
Shutdown/Logoff:

POWER         Sleep now
POWER         Hold for 10 seconds (force shut down)
Ctrl Eject    Restart, Sleep, Shutdown dialog box
⌘ Ctrl Eject  Quit all applications and restart
⌘ ⌥+ctrl+eject Graceful Shutdown
⌘ ⌥ Eject     Sleep now
⌘ ⌥ + Esc     Force Quit
⌘ + .(period) Stop a process
⌘ Ctrl+power  Immediate restart (dangerous, only if system is frozen)
Log out:

⌘ ⇧ Q         Log out (Apple Menu)
⌘ ⇧ ⌥ Q       Log out immediately (Apple Menu)
During Startup:

Shift      Safe Boot mode - Press shift asap AFTER the startup chime
⌘ V        Start up in Verbose mode.
⌘ S        Start up in Single-User mode (command line)
X          Force OS X startup
⌘ ⌥ ⇧ ⌫   Bypass primary startup volume (will seek DVD or external disk)
C          Start up from a CD that has a system folder
D          Start up from first partition
N          Attempt to start up from a network server(NetBoot)
R          Force PowerBook screen reset
T          Start up in FireWire Target Disk mode
⌘ ⌥ P R   PRAM Reset - Hold down Cmd-Option-R with your left hand,
then press POWER to start up and immediately press P with your right hand.
See KB 2238  At the prompt you can  type: reset-nvram and/or reset-all
⌘ ⌥ O F   Open Firmware
⌘ E        Eject CD (press during/after startup chime)
mouse      Eject CD (hold mouse button down during startup)

source