Skip to content

Instantly share code, notes, and snippets.

@timburks
Created February 9, 2009 21:05
Show Gist options
  • Save timburks/60996 to your computer and use it in GitHub Desktop.
Save timburks/60996 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/nush
(function append-to-file (filename text)
(unless ((NSFileManager defaultManager) fileExistsAtPath:filename)
((NSFileManager defaultManager) createFileAtPath:filename contents:nil attributes:nil))
(set handle (NSFileHandle fileHandleForWritingAtPath:filename))
(handle seekToEndOfFile)
(handle writeData:((+ text "\n") dataUsingEncoding:NSUTF8StringEncoding))
(handle closeFile))
;; example
(append-to-file "mylogfile" (+ "it is now " ((NSDate date) description)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment