Latest 100 public
snipts » mac
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; }];
-
∞ 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
-
∞ 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
-
∞ mount hfs+ (mac) file system on an external drive as read write in ubuntu (linux). depends on: hfsprogs
sudo fsck.hfsplus /dev/sdc1
-
∞ 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
-
∞ MacOS X all processes
--show all processes except Dashboard ps -cm -U username | awk '/:/ && $5!~/Dashboard/' -
∞ Hide Dock Icon in a plist
<key>NSUIElement</key> <string>1</string>
-
∞ show sockets on OS X
lsof -iTCP -n -P
-
∞ 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
-
∞ 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
-
∞ 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
-
∞ Enable mouseover highlights in stacks
$ defaults write com.apple.dock mouse-over-hilite-stack -boolean yes $ killall Dock
-
∞ 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
-
∞ Mac OS X's Single-Application Mode
# http://db.tidbits.com/article/10624 $ defaults write com.apple.dock single-app -bool true $ killall Dock
-
∞ 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
-
∞ 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
-
∞ 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
-
∞ 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
-
∞ 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
-
∞ 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


