Written by David on Thu, Nov 6, 2008 at 2:02am
Filed under OS X
Two among OS X’s more underutilised CLI tools are mdls and mdfind.
These both query the detailed metadata in Spotlight’s database (hence the md prefix). The first command will return all the attributes of a file or directory. The second will find all files that match a given attribute query string. O’Reilly’s MacDevCenter has an article detailing advanced use of these commands.
The first example uses Apple’s afplay, but since the AudioFile API seems to be incapable of understanding its own DRM (*.m4p), the second example uses qtplay from MacPorts.
Given the pervasive nature of Spotlight’s metadata, the possibilities are vast. Hint: SSH and “&”.
Written by David on Fri, Oct 17, 2008 at 3:36pm
Filed under JavaScript
JavaScript’s regular expression engine, while useful, lacks a few less frequently-used constructs.
I recently needed to remove all single whitespace characters (\s) immediately following semicolons (;) in a given block of text. A simple way to accomplish this uses the positive lookbehind construct – that is, to match certain characters (;), but not to consume them, only to assert whether a match occurred or not.
This would normally be written as:
text.replace(/(?<=;)\s/g, '');
Though JavaScript doesn’t support lookbehinds, we can use a lambda expression to mimic its zero-width assertion behaviour:
text.replace(/(\;|:)?\s/g, function(str, p1) {
return p1 ? p1 : str;
});
I haven’t tested this workaround exhaustively, but it solved the problem that needed to be overcome.
Update
It seems I’m not the first to have tackled this. Steve Levithan’s regex skills far exceed my own, and his blog entry on the subject offers a more comprehensive solution to the problem.
Written by David on Mon, Sep 29, 2008 at 12:09pm
Filed under iOS
If you have a jailbroken iPhone and find yourself unable to set the passcode lock, you can still activate this feature manually:
- set your passcode on the iPhone under Settings / General / Passcode Lock
(this stores the passcode, despite the feature not being activated)
- open /private/var/mobile/Library/Preferences/com.apple.springboard.plist on your phone;
the easiest way is to copy the file locally via SFTP, then edit it in the Property List Editor bundled with Xcode
- add the following key under Root:
- key = PasswordProtected
- type = Number
- value = 1
- restart SpringBoard (relaunch the process, or just restart your phone)
You can also reverse this process if you find yourself unable to access said iPhone.
Written by David on Tue, Sep 9, 2008 at 3:41pm
Filed under iOS
A recent upgrade to my iPhone left the phone unable to access visual voicemail. When I pushed the Voicemail button from the Phone screen, the phone simply did nothing.
Caveat: In addition to resetting your password, this will also delete your personal greeting. It shouldn’t affect existing messages, though this assumption is untested.
The solution:
- disable WiFi from the Settings menu
(visual voicemail needs to reset over EDGE or UMTS/3G)
- call AT&T at 611
- press 1 to confirm your number
- press 3 for voicemail help (press 5 for “Enterprise Customer Care”)
- press 3 to reset your password
- hang up and wait for a confirmation text message
The Voicemail screen should work again. Don’t forget to re-enable WiFi once you complete your voicemail setup.