IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » mac The latest public mac snipts.

showing 1-20 of 48 snipts for mac
  • get the index of the first occurrence of an object by class (using a block)
    /*
     * Some references:
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObjectPassingTest:
     *
     */
    
    /* Predeclare a block */
    BOOL (^IsSameClass)(id, NSUInteger, BOOL *) = ^(id element, NSUInteger idx, BOOL * stop) {
        *stop = [element isKindOfClass:UITabBar.class];
        return *stop;
    };
    	
    NSUInteger index = [myNSArray indexOfObjectPassingTest:IsSameClass];
    
    
    /* Using a block literal */
    NSUInteger index = [myNSArray indexOfObjectPassingTest:^(id element, NSUInteger idx, BOOL * stop){ 
        *stop = [element isKindOfClass:UITabBar.class];
        return *stop;
    }];
    

    copy | embed

    0 comments - tagged in  posted by jonatasmiguel on Sep 03, 2010 at 7:45 a.m. EDT
  • get the first occurrence of an object of a specific class
    /*
     * Some references:
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocFastEnumeration.html
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/isKindOfClass:
     *
     */
    
    /* NSArray+Additions.h */
    @interface NSArray (Additions) 
    
    - (id)objectOfClass:(Class)aClass;
    
    @end
    
    
    
    /* NSArray+Additions.m */
    #import "NSArray+Additions.h"
    
    
    @implementation NSArray (Additions)
    
    - (id)objectOfClass:(Class)aClass {
        for (id element in self) {
            if ([element isKindOfClass:aClass]) {
                return (element);
            }
        }
    
        return (nil);
    }
    
    @end
    

    copy | embed

    0 comments - tagged in  posted by jonatasmiguel on Sep 01, 2010 at 1:24 p.m. EDT
  • get the index of the first occurrence of an object by class
    /*
     * Some references:
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocFastEnumeration.html
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/isKindOfClass:
     *     http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/indexOfObject:
     *
     */
    
    /* NSArray+Additions.h */
    @interface NSArray (Additions) 
    
    - (NSInteger)indexOfObjectByClass:(Class)aClass;
    
    @end
    
    
    
    /* NSArray+Additions.m */
    #import "NSArray+Additions.h"
    
    
    @implementation NSArray (Additions)
    
    - (NSInteger)indexOfObjectByClass:(Class)aClass {
        for (id element in self) {
            if ([element isKindOfClass:aClass]) {
                return ([self indexOfObject:element]);
            }
        }
    
        return (-1);
    }
    
    @end
    

    copy | embed

    0 comments - tagged in  posted by jonatasmiguel on Sep 01, 2010 at 11:44 a.m. EDT
  • mount hfs+ (mac) file system on an external drive as read write in ubuntu (linux). depends on: hfsprogs
    sudo fsck.hfsplus /dev/sdc1
    

    copy | embed

    0 comments - tagged in  posted by defyenterprises on Aug 05, 2010 at 3:15 a.m. EDT
  • AppleScript to save and restore window positions
    #!/usr/bin/osascript
    
    -- Usage:
    -- $ osacompile -o windowPositions.compiled.scpt windowPositions.scpt
    -- $ osascript windowPositions.compiled.scpt --save
    -- $ osascript windowPositions.compiled.scpt --restore
    
    -- Change this to be the list of windows you want to save/restore
    property affectedProcesses : {"Chrome", "Adium", "Eclipse", "Terminal"}
    property windowRecord : {}
    
    on run argv
    	if (count of argv) is equal to 0 then
    		log "Please specify one of --save or --restore."
    		return
    	end if
    	
    	tell application "System Events"
    		if (item 1 of argv is equal to "--save") then
    			set windowRecord to {}
    			repeat with i from 1 to count affectedProcesses
    				set end of windowRecord to {0, {}, {}}
    			end repeat
    			repeat with p from 1 to count affectedProcesses
    				set processName to (item p of affectedProcesses)
    				if exists process processName then
    					log "Process '" & processName & "' exists"
    					tell process processName
    						set numWindows to count windows
    						set item 1 of item p of windowRecord to numWindows
    						repeat with i from 1 to numWindows
    							set end of item 2 of item p of windowRecord to position of window i
    							set end of item 3 of item p of windowRecord to size of window i
    						end repeat
    					end tell
    				end if
    			end repeat
    		else
    			repeat with p from 1 to count affectedProcesses
    				set processName to (item p of affectedProcesses)
    				if exists process processName then
    					log "Process '" & processName & "' exists"
    					tell process processName
    						set numWindows to item 1 of item p of windowRecord
    						repeat with i from 1 to numWindows
    							set position of window i to (item i of item 2 of item p of windowRecord)
    							set size of window i to (item i of item 3 of item p of windowRecord)
    						end repeat
    					end tell
    				end if
    			end repeat
    		end if
    	end tell
    end run
    

    copy | embed

    2 comments - tagged in  posted by Fotinakis on Jun 11, 2010 at 2:23 p.m. EDT
  • MacOS X all processes
    --show all processes except Dashboard
    ps -cm -U username | awk '/:/ && $5!~/Dashboard/'
    

    copy | embed

    0 comments - tagged in  posted by d13t on Apr 28, 2010 at 3:47 a.m. EDT
  • Hide Dock Icon in a plist
    <key>NSUIElement</key>
    <string>1</string>
    

    copy | embed

    0 comments - tagged in  posted by joeybaker on Mar 29, 2010 at 2:48 p.m. EDT
  • show sockets on OS X
    lsof -iTCP -n -P
    

    copy | embed

    0 comments - tagged in  posted by febeling on Mar 15, 2010 at 9:17 a.m. EDT
  • Script to automate OCR with Adobe Acrobat using Hazel for Mac
    try
       tell application "Adobe Acrobat Professional"
          activate
          open theFile
          tell application "System Events"
             tell process "Acrobat"
                tell menu bar 1
                   tell menu "Document"
                      tell menu item "OCR Text Recognition"
                         tell menu 1
                            click menu item "Recognize Text Using OCR..."
                         end tell
                      end tell
                   end tell
                   
                end tell
                keystroke return
             end tell
          end tell
          save the front document
          close the front document
       end tell
    end try
    

    copy | embed

    0 comments - tagged in  posted by macdrifter on Mar 02, 2010 at 5:15 p.m. EST
  • Enable automatic revision control for SVN on any client/IDE
    # Enable automatic revision control for SVN on any client/IDE like Coda (Mac) or others.
    # This means that you can include copyrights in your files and
    # SVN will make sure it revises the files accordingly if you use the $id$ variable within them.
    # Add the following lines right at the bottom of the SVN config file located in:
    # ~/.subversion/config (Mac/Linux)
    
    [miscellany]
    enable-auto-props = yes
    
    [auto-props]
    # Scriptish formats
    *.bat        = svn:eol-style=native; svn:keywords=Id; svn-mine-type=text/plain
    *.bsh        = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/x-beanshell
    *.cgi        = svn:eol-style=native; svn:keywords=Id; svn-mine-type=text/plain
    *.cmd        = svn:eol-style=native; svn:keywords=Id; svn-mine-type=text/plain
    *.js         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/javascript
    *.php        = svn:eol-style=native; svn:keywords=Id Rev Date; svn:mime-type=text/x-php
    *.pl         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/x-perl; svn:executable
    *.pm         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/x-perl
    *.py         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/x-python; svn:executable
    *.sh         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/x-sh; svn:executable
    
    # Image formats
    *.bmp        = svn:mime-type=image/bmp
    *.gif        = svn:mime-type=image/gif
    *.ico        = svn:mime-type=image/ico
    *.jpeg       = svn:mime-type=image/jpeg
    *.jpg        = svn:mime-type=image/jpeg
    *.png        = svn:mime-type=image/png
    *.tif        = svn:mime-type=image/tiff
    *.tiff       = svn:mime-type=image/tiff
    
    # Data formats
    *.pdf        = svn:mime-type=application/pdf
    *.avi        = svn:mime-type=video/avi
    *.doc        = svn:mime-type=application/msword
    *.eps        = svn:mime-type=application/postscript
    *.gz         = svn:mime-type=application/gzip
    *.mov        = svn:mime-type=video/quicktime
    *.mp3        = svn:mime-type=audio/mpeg
    *.ppt        = svn:mime-type=application/vnd.ms-powerpoint
    *.ps         = svn:mime-type=application/postscript
    *.psd        = svn:mime-type=application/photoshop
    *.rtf        = svn:mime-type=text/rtf
    *.swf        = svn:mime-type=application/x-shockwave-flash
    *.tgz        = svn:mime-type=application/gzip
    *.wav        = svn:mime-type=audio/wav
    *.xls        = svn:mime-type=application/vnd.ms-excel
    *.zip        = svn:mime-type=application/zip
    
    # Text formats
    .htaccess    = svn:mime-type=text/plain
    *.css        = svn:mime-type=text/css
    *.dtd        = svn:mime-type=text/xml
    *.html       = svn:mime-type=text/html
    *.ini        = svn:mime-type=text/plain
    *.sql        = svn:mime-type=text/x-sql
    *.txt        = svn:mime-type=text/plain
    *.xhtml      = svn:mime-type=text/xhtml+xml
    *.xml        = svn:mime-type=text/xml
    *.xsd        = svn:mime-type=text/xml
    *.xsl        = svn:mime-type=text/xml
    *.xslt       = svn:mime-type=text/xml
    *.xul        = svn:mime-type=text/xul
    *.yml        = svn:mime-type=text/plain
    CHANGES      = svn:mime-type=text/plain
    COPYING      = svn:mime-type=text/plain
    INSTALL      = svn:mime-type=text/plain
    Makefile*    = svn:mime-type=text/plain
    README       = svn:mime-type=text/plain
    TODO         = svn:mime-type=text/plain
    
    # Code formats
    *.c          = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    *.cpp        = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    *.h          = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    *.java       = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    *.as         = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    *.mxml       = svn:eol-style=native; svn:keywords=Id; svn:mime-type=text/plain
    

    copy | embed

    0 comments - tagged in  posted by fevangelou on Dec 11, 2009 at 2:07 p.m. EST
  • install mysql gem in mac
    # MySQL gem for Snow Leapord
    sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
    

    copy | embed

    0 comments - tagged in  posted by chawei on Dec 04, 2009 at 2:19 a.m. EST
  • Enable mouseover highlights in stacks
    $ defaults write com.apple.dock mouse-over-hilite-stack -boolean yes
    $ killall Dock 
    

    copy | embed

    0 comments - tagged in  posted by softdev on Oct 12, 2009 at 10:30 a.m. EDT
  • Enable "path view" in Finder
    # http://www.tuaw.com/2008/12/05/terminal-tips-enable-path-view-in-finder/
    
    $ defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
    $ killall Finder
    

    copy | embed

    0 comments - tagged in  posted by siggiarni on Oct 06, 2009 at 6:44 p.m. EDT
  • Mac OS X's Single-Application Mode
    # http://db.tidbits.com/article/10624
    
    $ defaults write com.apple.dock single-app -bool true
    $ killall Dock
    

    copy | embed

    0 comments - tagged in  posted by siggiarni on Oct 06, 2009 at 6:38 p.m. EDT
  • ISO-DMG Conversion
    # Convert a DMG file to ISO
    hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso
    # Convert an ISO file to DMG format
    hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg
    

    copy | embed

    0 comments - tagged in  posted by goerz on Sep 09, 2009 at 3:43 p.m. EDT
  • remove spotlight
    # Remove Spotlight from the Menu Bar (works on Snow Leopard)
    # restart the SystemUIServer!
    # /System/Library/CoreServices> 
    sudo mv Search.bundle/ Search.bundle.disabled
    

    copy | embed

    1 comment - tagged in  posted by goerz on Sep 03, 2009 at 5:37 a.m. EDT
  • disable Spotlight
    // 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
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 27, 2009 at 3:30 a.m. EDT
  • Manual Mounting on Mac
    #! /bin/bash
    # Mount a partition described in /etc/fstab
    # For example fstab could contain the line
    # LABEL=PARTITION_NAME none msdos rw,noauto
    # See http://www.macosxhints.com/article.php?story=20090811124320441
    
    dev_id=`diskutil list | awk '/PARTITION_NAME/{ print $6; }'`
    [[ $dev_id ]] && diskutil mount $dev_id
    

    copy | embed

    0 comments - tagged in  posted by goerz on Aug 25, 2009 at 2:52 p.m. EDT
  • symbolic link
    #syntax to create symbolic link
    ln -s /export/space/common/archive /archive
    
    #example, link would be created in directory 'placement'
    ln -s /path/to/original/file/or/directory /path/to/the/placement
    
    #dropbox example
    ln -s /Users/username/Dropbox/theFolder /path/to/symbolic/links/directory
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 21, 2009 at 8:24 a.m. EDT
  • Clean Mail.app Database
    1. Quit mail
    2. Load terminal
    3. cd ~/Library/Mail
    4. sqlite3 Envelope\ Index
    5. at the 'sqlite>' prompt, enter 'vacuum subjects;' and then 'vacuum;'
    6. Reload mail - it may well be faster loading and your search may well work again!
    
    cd ~/Library/Mail
    sqlite3 Envelope\ Index
    vacuum subjects;
    vacuum;
    .exit
    

    copy | embed

    1 comment - tagged in  posted by joeybaker on Aug 20, 2009 at 8:30 p.m. EDT
Sign up to create your own snipts, or login.