Wrapping ‘defaults’ to be more flexible…
Thursday, November 22nd, 2007So I don’t know about any of you, gentle readers, but ‘defaults’ really gives me the shits sometimes.
Exhibit A:
/ $ defaults read /Library/Preferences/com.apple.loginwindow.plist 2007-11-21 13:12:04.288 defaults[97501:10b] Domain com.apple.loginwindow.plist does not exist / $ defaults read /Library/Preferences/com.apple.loginwindow (snip actual working output)
Exhibit B:
/ $ cd /Library/Preferences /Library/Preferences $ defaults read ./com.apple.loginwindow.plist 2007-11-21 13:13:24.327 defaults[97540:10b] Domain ./com.apple.loginwindow.plist does not exist /Library/Preferences $ defaults read ./com.apple.loginwindow 2007-11-21 13:13:25.799 defaults[97546:10b] Domain ./com.apple.loginwindow does not exist
This really annoys me, that ‘defaults’ firstly doesn’t accept the full path to the plist, when other tools like ‘launchctl’ do, and requires that you strip off the “.plist” from the end, and secondly, that you can’t use relative paths.
This annoyed me so much that I decided to finally do something about it. This function resolves both problems.
function defread { defaults read $(echo "$@" | sed "s|\./|`pwd`/|g" | sed "s|.plist||g"); }
And now we can do:
/ $ defread /Library/Preferences/com.apple.loginwindow.plist / $ cd /Library/Preferences /Library/Preferences $ defread ./com.apple.loginwindow.plist
or even:
/Library/Preferences $ defread ./com.apple.loginwindow.plist SHOWFULLNAME 1
mmmm.



