#!/usr/bin/env nush ; Useful script for when you have a rotating background on Mac OS X ; this script will tell you which image is currently being displayed. ; If you add -rm when calling the command then it will provide you with ; prompt to let you delete the background. ; ; Installation: ; Copy this into something like ~/bin/current_background and then ; $ chmod 750 ~/bin/current_background ; then use :D ; ; Bugs: ; 1. When prompting for user input I can't seem to flush stdout manually ; so I have to print a new line character in order to show the prompt. ; (set processInfo (NSProcessInfo processInfo)) (set args (processInfo arguments)) (if (and (eq (args count) 3) (eq (args objectAtIndex:2) "-rm")) (set shouldOfferToRemove t) (else (set shouldOfferToRemove nil))) ;; Get the dictionary (set plist ("~/Library/Preferences/com.apple.desktop.plist" stringByExpandingTildeInPath)) (set prefs (NSDictionary dictionaryWithContentsOfFile:plist)) ;; Drill down to the dictionary key we care about (set default ((prefs valueForKey:"Background") valueForKey:"default")) ;; Extract the fields we need (set changePath (default valueForKey:"ChangePath")) (set currentImage (default valueForKey:"LastName")) ;; Print the information (puts "Current desktop image is #{currentImage}") ;; Offer to delete (if (eq t shouldOfferToRemove) (print "Are you sure you want to delete #{currentImage} [y/N]: \n") (set input (((NSString alloc) initWithData:((NSFileHandle fileHandleWithStandardInput) availableData) encoding:NSUTF8StringEncoding) stringByTrimmingCharactersInSet: (NSCharacterSet whitespaceAndNewlineCharacterSet))) (if (or (input isEqualToString:"y") (input isEqualToString:"Y")) (set fm (NSFileManager defaultManager)) (set path (changePath stringByAppendingPathComponent:currentImage)) (if (fm removeFileAtPath:path handler:nil) (puts "Background #{currentImage} has been deleted") (else (puts "Background #{currentImage} could not be deleted"))) (else (puts "Background #{currentImage} has not been deleted"))))