CodeBeach.org Submissions http://codebeach.org/code/list CodeBeach.org submission feed en-us Sun, 15 Apr 2007 12:31:39 -0400 NSCharacterSet (BSNewLineCharacterSet) http://codebeach.org/code/show/1 http://codebeach.org/code/show/1 This is a simple category of NSCharacterSet which adds a commodity method to create a set composed only of the newline character.<br /><br /> Sun, 15 Apr 2007 12:35:01 -0400 BSSingleLineFormatter http://codebeach.org/code/show/2 http://codebeach.org/code/show/2 Is a formatter (subclass of NSFormatter) which removes the newlines encountered in input. This can be used to avoid newlines characters to get in NSTextFields, for example by copy&amp;pasting.<br /><br /> Sun, 15 Apr 2007 12:44:54 -0400 BSHotKey http://codebeach.org/code/show/3 http://codebeach.org/code/show/3 Plugin that adds global hotkey support to any application that loads it. <br /> <br />Usage: compile, copy the resulting bundle into your application's plugin folder and tell the app to load the bundle. Register a hotkey with name, target and action to the manager and you are ready to go. <br /> <br />Add the managers prefs view to your application's prefs window to change the hotkey (by default you don't have any hotkey set). <br />Hotkeys are stored/loaded to the user defaults automatically. <br /> <br />See the project for an example Application that makes use of the plugin.<br /><br /> Sun, 15 Apr 2007 12:50:26 -0400 BSByteFormatter http://codebeach.org/code/show/4 http://codebeach.org/code/show/4 This is a formatter (NSFormatter subclass) which converts NSNumber instances representing mostly sizes in bytes and converts them to a human readable string (2048 =&gt; &quot;2 KB&quot;). It supports unit of measure up to the Terabyte. Note that input is assumed to be an NSNumber and no checks are performed about it.<br /><br /> Sun, 15 Apr 2007 12:59:34 -0400 BSPluginLoader http://codebeach.org/code/show/5 http://codebeach.org/code/show/5 BSPluginLoader is a loadable bundle that allows applications to easily load plugins. The plugins can be installed in any applications support folder or in the application's bundle itself.<br /><br /> Sun, 15 Apr 2007 13:02:20 -0400 NSWorkspace (BSInvisibility) http://codebeach.org/code/show/6 http://codebeach.org/code/show/6 This category to NSWorkspace adds the method “isInvisibleFileAtPath:” which checks wether the file at a given path is invisible or not. On Mac OS X there are many ways of making a file invisible, this method will check all, and has some hardcoded paths, it reflects visibility in Finder.app.<br /><br /> Sun, 15 Apr 2007 14:56:14 -0400 Snippet #7 http://codebeach.org/code/show/7 http://codebeach.org/code/show/7 This code access to the low-level framebuffer and can be used for example to take screenshots. This code can be easily adapted to Intel, where the alpha channel should be the last.<br /><br /> Mon, 16 Apr 2007 12:33:40 -0400 BSLabeledIconCell http://codebeach.org/code/show/8 http://codebeach.org/code/show/8 An NSTextFieldCell subclass which displays both an image and a label. It can be used for example in file listing, inside an NSTableView or NSOutlineView to show both the icon and the name of a file.<br /><br /> Mon, 16 Apr 2007 12:38:53 -0400 BSSidebar http://codebeach.org/code/show/9 http://codebeach.org/code/show/9 This NSTableView subclass tries to mimic the appearance of the Finder sidebar using gradients to highlight selections. I suggest replacing the png's gradients with some vector art looking towards Leopard. <br /> <br />You probably also want to download BSLabeledIconCell to have a cell which displays both an icon and a label on a single column, but is not a strict dependency.<br /><br /> Mon, 16 Apr 2007 12:41:12 -0400 NSOutlineView (BSMultipleRowFetch) http://codebeach.org/code/show/10 http://codebeach.org/code/show/10 A very simple NSOutlineView category which adds a method to fetch all the rows specified in an NSIndexSet with a single method call.<br /><br /> Mon, 16 Apr 2007 12:43:32 -0400 NSWorkspace (BSDriveRecognition) http://codebeach.org/code/show/11 http://codebeach.org/code/show/11 This NSWorkspace category allows you to discern between mounted physical volumes and network volumes. Please note that currently only webdav volumes are recognized as network drives, however this can be easily fixed by simply adding some string comparisons at the end of the -isNetworkVolumeAtPath: which the desired network volumes.<br /><br /> Thu, 19 Apr 2007 07:14:37 -0400 Snippet #12 http://codebeach.org/code/show/12 http://codebeach.org/code/show/12 How to change window tags, in this example it uses the shadow flag, but it can also be used for expose flags, mouse-event transparency and the sticky flag <br /> <br />CGSClearWindowTags will _clear_ the tags that are set in tags and CGSSetWindowTags will _set_ the tags<br /><br /> Mon, 23 Apr 2007 02:14:52 -0400 UKFilePathView http://codebeach.org/code/show/13 http://codebeach.org/code/show/13 An NSView that displays a file path. This looks kind of like how Sherlock displays the location of a file. Basically you get each folder's display name with its icon in front of it, and little grey triangles between them, and you get the icon of each file or folder and its display name. <br /> <br />If the path is too long, this takes items out of the middle and displays an ellipsis character (...) instead. <br /> <br />You can also right-click or control-click on this to get a contextual menu that contains &quot;Reveal in Finder&quot; and &quot;Show Real Names&quot; menu choices. Real names displays the actual path, starting with &quot;/&quot;, and using the actual file names instead of their display names. As a shortcut, double-clicking this view is the same as &quot;Reveal in Finder&quot;. <br /> <br />Finally, this also lets you hook up buttons to the view to let you choose an existing, or new file or folder name. <br /><br /> Mon, 23 Apr 2007 02:19:22 -0400 UKLoginItemRegistry http://codebeach.org/code/show/14 http://codebeach.org/code/show/14 A Cocoa wrapper class around Apple's LoginItemsAE sample code. Get Apple's LoginItemsAE code at: <br /> <br />http://developer.apple.com/samplecode/LoginItemsAE/index.html<br /><br /> Mon, 23 Apr 2007 02:22:13 -0400 UKXattrMetadataStore http://codebeach.org/code/show/15 http://codebeach.org/code/show/15 A wrapper around the MacOS X 10.4 xattr APIs for attaching metadata to files. Also offers convenience methods for dealing with UTF8 strings and property-list-objects as the metadata values.<br /><br /> Mon, 23 Apr 2007 02:27:46 -0400 UKToolbarFactory http://codebeach.org/code/show/16 http://codebeach.org/code/show/16 A simple delegate class that you can drop into a NIB file to add a simple toolbar to your application. You specify the list of allowed items and the default list of items in a .plist file, hook it up to the window and it will automatically be configurable and save automatically. <br /> <br />It also supports simple view-based and selectable items. <br /> <br /><br /> Mon, 23 Apr 2007 02:36:52 -0400 NSWindow (UKFlipWindow) http://codebeach.org/code/show/17 http://codebeach.org/code/show/17 An NSWindow category which replicates Dashboard's &quot;flip over a window to see its back side&quot; effect. I'm doing all of this manually (NSAffineTransform seems to only let you rotate and scale stuff), so it isn't blazingly fast, but maybe it's of use to someone. <br /><br /> Mon, 23 Apr 2007 02:43:42 -0400 UKSpeechSynthesizer http://codebeach.org/code/show/18 http://codebeach.org/code/show/18 A wrapper class around the Carbon SpeechChannel that tries to be compatible with but also expands upon the features of Apple's NSSpeechChannel. <br /> <br />Also included is UKSpeechSettingsView, which provides a simple user interface for modifying the settings of a speech channel<br /><br /> Mon, 23 Apr 2007 02:46:05 -0400 UKIdleTimer http://codebeach.org/code/show/19 http://codebeach.org/code/show/19 This is a wrapper around the Carbon EventLoopIdleTimer, intended to be used just like an NSTimer. An Idle Timer doesn't trigger until the user has been idle for a while, doing nothing in the GUI of the current application.<br /><br /> Mon, 23 Apr 2007 02:47:36 -0400 UKFontMenuController http://codebeach.org/code/show/20 http://codebeach.org/code/show/20 A small class that you hook up to your &quot;Format&quot; menu to append a font menu to your menu bar. It will automatically list all collections (or a specific one) from the font panel and thus provide quick access to all your fonts without having to open the font panel.<br /><br /> Mon, 23 Apr 2007 02:49:28 -0400 UKDocumentationController http://codebeach.org/code/show/21 http://codebeach.org/code/show/21 A small handy drop-in class lets you easily add menu items that show the &quot;Readme&quot;, &quot;Release Notes&quot; and &quot;FAQ&quot; sections of your application's help book. Simply looks up the appropriate anchors.<br /><br /> Mon, 23 Apr 2007 02:57:35 -0400 UKKQueue http://codebeach.org/code/show/22 http://codebeach.org/code/show/22 A wrapper class around the kqueue file change notification mechanism. <br /> <br />Simply create a UKKQueue, add a few paths to it and listen to the change notifications via NSWorkspace's notification center or delegate messages. <br /><br /> Mon, 23 Apr 2007 03:02:16 -0400 UKPrefsPanel http://codebeach.org/code/show/23 http://codebeach.org/code/show/23 A simple delegate class that makes it easy to create a simple Preferences window. Put your different preference panes in a tabless NSTabView, connect that to an instance of UKPrefsPanel, and you automatically get a toolbar with icons for each tab pane that switch between the tabs. <br /><br /> Mon, 23 Apr 2007 03:05:00 -0400 UKDockProgressIndicator http://codebeach.org/code/show/24 http://codebeach.org/code/show/24 A class that shows a small determinate progress bar overlaid over your application's dock icon. <br /> <br />This is intended as a drop-in replacement for the NSProgressIndicator view, as it understands the same messages. You can even have the dock progress indicator forward all calls to the view, thus driving both without changing your existing code.<br /><br /> Mon, 23 Apr 2007 03:06:32 -0400 UKDirectoryEnumerator http://codebeach.org/code/show/25 http://codebeach.org/code/show/25 A faster, more configurable variant of NSDirectoryEnumerator. Uses the Carbon FSGetCatalogInfoBulk() call under the hood to do its work, and gives you greater control over what additional file info you want. One advantage of this is that you get HFS-specific file info (file type, creator, Finder flags, resource fork sizes) for free.<br /><br /> Mon, 23 Apr 2007 03:08:42 -0400 UKCrashReporter http://codebeach.org/code/show/26 http://codebeach.org/code/show/26 A simple function that you can call at application startup to send crash reports for your application to a CGI on your server. <br /><br /><br /> Mon, 23 Apr 2007 03:17:06 -0400 UKDebugNames http://codebeach.org/code/show/27 http://codebeach.org/code/show/27 A little debugging helper function that assigns each pointer a name. That way, you can NSLog() pointers and will get nice, memorable names instead of 0x00848400. <br /><br /> Mon, 23 Apr 2007 03:20:54 -0400 NSWindow (UKFade) http://codebeach.org/code/show/28 http://codebeach.org/code/show/28 This is a little extension to NSWindow in the form of a category that adds a few methods for fading in/out a window. <br /><br /><br /> Mon, 23 Apr 2007 13:53:50 -0400 Snippet #29 http://codebeach.org/code/show/29 http://codebeach.org/code/show/29 Function that returns true if all bytes in a buffer are NULL. This is useful for testing whether opaque structures like FSRef are valid, presumably after having been bzero'd.<br /><br /> Mon, 23 Apr 2007 15:11:03 -0400 Snippet #30 http://codebeach.org/code/show/30 http://codebeach.org/code/show/30 Work around SoundManager buffer-level byte-swapping on Intel hardware. CFSwapInt32 compiles down to a single bswap32 instruction. Call like so: <br />FloatArrayByteSwapOnIntel(mixBuffer, bufferSamples);<br /><br /> Mon, 23 Apr 2007 16:23:52 -0400 Snippet #31 http://codebeach.org/code/show/31 http://codebeach.org/code/show/31 Objective-C class method to set the invisibility flag of a file.<br /><br /> Wed, 25 Apr 2007 20:16:22 -0400 NSString (ComBelkadanUtilsKVO) http://codebeach.org/code/show/32 http://codebeach.org/code/show/32 A category for the rare instances where you need to use KVO with NSString/NSMutableString. This allows you to use the key &quot;string&quot; for KVO or Cocoa bindings. <br /> <br />Example usage: binding to an NSArrayController that refers to an array of mutable strings. (Without a key path you get an error.) <br /> <br />Note: full name of the category is ComBelkadanUtils_NSStringKVO to avoid name collisions. You can change this if you want.<br /><br /> Wed, 25 Apr 2007 20:54:37 -0400 ComBelkadanUtilsFilePathFormatter http://codebeach.org/code/show/33 http://codebeach.org/code/show/33 Formats an absolute file path into its display name. When the user edits the field the entire path is shown. By default, also tries to autocomplete a path entered by the user, and only allows paths starting with the root folder (/) or home folder (~). <br /> <br />The full name of this class is ComBelkadanUtils_FilePathFormatter; for convenience it is #define'd in the header file to FilePathFormatter. YOU MUST USE THE FULL NAME IN INTERFACE BUILDER.<br /><br /> Thu, 26 Apr 2007 09:45:48 -0400 NDAlias http://codebeach.org/code/show/34 http://codebeach.org/code/show/34 NDAlias is a wrapper for Apples Alias Records, there is and optional category that add methods for initialising NDAliases from alias files and writing NDAliases to alias files but this is not it's main function of NDAlias. <br /><br /><br /> Thu, 26 Apr 2007 10:12:11 -0400 Snippet #35 http://codebeach.org/code/show/35 http://codebeach.org/code/show/35 Resizes a NSSplitView in a nice fashion allowing for minimum splitview restraints for the left panel<br /><br /> Sat, 12 May 2007 08:49:41 -0400 ESSTimeTrialClass http://codebeach.org/code/show/36 http://codebeach.org/code/show/36 This class has one simple purpose: Terminate the application, once a certain date has been reached. <br />You just pass the class a date (the date the trial should end) and a termination message and the class does the rest. <br />If the date is before the current date, it will terminate immediately (showing a termination message), if it's some where in the future, it will start a timer and will then terminate the application.<br /><br /> Mon, 21 May 2007 10:33:27 -0400 ESSImageCategory http://codebeach.org/code/show/37 http://codebeach.org/code/show/37 This will make it possible for you not only to get a TIFFRepresentation, but also JPEGRepresentation, JPEG2000Representation, PNGRepresentation, GIFRepresentation, BMPRepresentation.<br /><br /> Sun, 27 May 2007 13:08:03 -0400 Snippet #39 http://codebeach.org/code/show/39 http://codebeach.org/code/show/39 Add/Remove your app from Login Items <br /> <br />These are two methods to add and remove your program from the Login Items list in Mac OS X 10.4. <br />I didn't write most of the code. It Originally came from http://www.cocoadev.com/index.pl?StartingMyAppOnStartup <br />I split the original code into 2 methods and made it automatically detect the name of your app. <br /> <br />-You don't have to modify anything to add these to your app. Just drop them into your code. <br />-OS X keeps the addToLoginItems method from adding your app twice. (sweet!) <br />-You don't have to check if your app is already listed. The removeFromLoginItems method does it for you. <br />-This, to me, seem MUCH easier than using Apple's LoginItemsAE class.<br /><br /> Sat, 14 Jul 2007 09:38:52 -0400 Snippet #40 http://codebeach.org/code/show/40 http://codebeach.org/code/show/40 These functions are useful if you communicate with a Java application via the JNI. As their name implies they are used to convert NSStrings to Java strings and viceversa.<br /><br /> Sun, 15 Jul 2007 11:23:47 -0400 NSString (NDCarbonUtilities) http://codebeach.org/code/show/41 http://codebeach.org/code/show/41 This category to NSString adds method to create strings from FSRef and viceversa. It also adds a method to resolve file aliases<br /><br /> Sun, 15 Jul 2007 11:26:36 -0400 UKSoundFileRecorder http://codebeach.org/code/show/42 http://codebeach.org/code/show/42 This is a Cocoa class that uses CoreAudio to record sound from the system's default sound input and writes it to a file. <br /><br /><br /> Sat, 21 Jul 2007 12:00:35 -0400 BSJobList http://codebeach.org/code/show/43 http://codebeach.org/code/show/43 BSJobList opens a simple window with a list of checkboxes. these checkboxes represent jobs that can be performed. each job that is checked is executed after ok is pressed. Everything is provided as a bundle so it's easy to integrate into other applications.... for more information look here: http://briksoftware.com/blog/?p=50<br /><br /> Sun, 22 Jul 2007 03:19:24 -0400 ZNLog http://codebeach.org/code/show/44 http://codebeach.org/code/show/44 How many times have you found yourself coding some “sick cocoa code… gosh” (excuse the Napoleon Dynamite reference there), and thought - “Gee whiz Myself, NSLog sure is sorta limp in the actual informative-ness stakes, ain’t it?” <br /> <br />Me? All the time. So I did a bit of hunting about and devised the following logging class based upon comments by Scott Morrison at http://outerlevel.com/blog/2006/12/01/code-review/. It will show the file, parent method and line number of the point where the ZNLog method is called - very tasty! <br /> <br />It’s all licensed under Creative Commons Attribution 2.5 license, so just be sure to include a short attribution back to me in your header/notes/readme. <br /><br /><br /> Tue, 31 Jul 2007 21:17:44 -0400 Snippet #45 http://codebeach.org/code/show/45 http://codebeach.org/code/show/45 GetUUID(): Quickly generate a UUID using Core Foundation. <br /><br /><br /> Wed, 29 Aug 2007 16:30:42 -0400 NSFileManager (BSAliasResolving) http://codebeach.org/code/show/52 http://codebeach.org/code/show/52 A very simple category adding a method to resolve aliases from NSFileManager. The actual implementation is from some example on Apple documentation, slightly adapted. It works reliably for both aliases of files and folder.<br /><br /> Thu, 13 Sep 2007 19:38:22 -0400 PWPolishedSlider http://codebeach.org/code/show/53 http://codebeach.org/code/show/53 This is a volume slider that looks like the slider from iTunes. Does not support ticked sliding.<br /><br /> Thu, 20 Sep 2007 19:27:00 -0400 PWLevelIndicator http://codebeach.org/code/show/54 http://codebeach.org/code/show/54 I noticed that the current star rating level indicator style really sucks. So I took it upon myself to make a custom star rater. You can easily change around the images, and size (you have to do this in the .m file though.) The images that come with it look nice for a polished (or unified as some people call it) window like in iTunes.<br /><br /> Sat, 22 Sep 2007 08:32:58 -0400 BSCrashNotifier http://codebeach.org/code/show/55 http://codebeach.org/code/show/55 BSCrashNotifier is a bundle that allows you to be notified when your app is crashing. <br /> <br />use it with: <br /> <br /> NSBundle* bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@&quot;BSCrashNotifier&quot; ofType:@&quot;bundle&quot;]]; <br /> Class crashNotifierClass = [bundle principalClass]; <br /> if (crashNotifierClass) <br /> { <br /> [crashNotifierClass onCrashSend:@selector(weCrashed:) to:self]; <br /> } <br /> else <br /> { <br /> NSLog(@&quot;couldn't load bundle&quot;); <br /> } <br /> <br />and implement the notification method like: <br />- (void)weCrashed:(int)signalNumber <br />{ <br /> NSLog(@&quot;we crashed: %i&quot;,signalNumber); <br />} <br /> <br /><br /><br /> Thu, 01 Nov 2007 18:05:49 -0400 Snippet #56 http://codebeach.org/code/show/56 http://codebeach.org/code/show/56 This code allows to start a Java Virtual Machine inside an application avoiding crashes which may be caused by having classpath items containing the &quot;:&quot; character in their paths, which is also classpath separator character (and Mac OS X way of storing the / character for file names). If you aren't sure that your application won't be placed in a path containing that character somewhere, this little hacks allows you to only write the name of the jars you wish to include in the classpath by telling it where to find them beforehand. basePath is the directory where those as stored which is most likely computed at runtime (for example by asking NSBundle) and may contain the problematic character.<br /><br /> Fri, 11 Jan 2008 12:02:28 -0500 Snippet #57 http://codebeach.org/code/show/57 http://codebeach.org/code/show/57 This is a sample trampoline application, aiming to simply installation&amp;update of command line tools by Cocoa application. Take a look at http://briksoftware.com/blog/?p=70 for more informations.<br /><br /> Sun, 09 Mar 2008 15:27:41 -0400 NSString+FourCharCode http://codebeach.org/code/show/58 http://codebeach.org/code/show/58 Convenience methods to convert an NSString into a FourCharCode (or derived type like an OSType) and back again. Useful for Launch Services and such.<br /><br /> Wed, 09 Apr 2008 05:15:11 -0400 Snippet #59 http://codebeach.org/code/show/59 http://codebeach.org/code/show/59 Leopard sends all NSlog() to syslog - what a pain in the debugger! This is similar to snippet ZNLog but my implementation is invoked with a preprocessor macro and the log line has a time of day stamp and file path reduced to just the file name. <br /> <br />I presume this should work in all versions of Mac OS X but I've only used it with Leopard. You need no declaration to call the function unless your use is in the same file it is and appears earlier. <br /> <br />No copyright; do what you want with it.<br /><br /> Thu, 15 May 2008 18:50:28 -0400 NSObject+PropertyListCopying http://codebeach.org/code/show/60 http://codebeach.org/code/show/60 Convenience members for deep-copying property lists. This method will default back to shallow copies for objects other than NSArray and NSDictionary.<br /><br /> Mon, 14 Jul 2008 16:47:15 -0400 Snippet #61 http://codebeach.org/code/show/61 http://codebeach.org/code/show/61 An NSString ObjC category meant as an enhanced version of [myString capitalizedString]. <br />It allows you to feed it with an array of words to be used with their very own capitalization (to protect words like &quot;McCartney&quot;)<br /><br />