I was recently asked to see if I could copy over the custom page sizes from a Snow Leopard machine over to a Lion machine.
While finding the right file in ~/Library/Preferences (com.apple.print.custompapers.plist) wasn't so difficult, it turned out that the Snow Leopard version of the file is binary encoded while the Lion version is not. (It may be that this file was grandfathered in from a previous system.)
XCode for Lion can convert the file to a regular XML text file:
Open the file in Xcode.
Choose File > Duplicate.
In the Save dialog box, select "Property List XML" from the Format drop-down list.
Moving the regular text version over to Lion and putting it into the Preferences folder gave us a way to copy a huge list of custom paper sizes from one designer to another quickly and easily.
Note: An updated version of this script (in fact two new scripts) has been posted as a new hint. These new scripts take into account many of the comments posted below. Please see the new hint to find the improved version.
Here's an AppleScript that presents a dialog box listing mounted local volumes, one or more of which can be selected for unmounting. Some solutions for doing this either require the use of additional system resources or are offered commercially. This AppleScript is free, of course. I’ve only tested it in Lion so far. I recommend that you set up a keyboard shortcut that launches the AppleScript either as part of a Mac OS X Automator Service, or from the Script menu, which (in Lion) can be configured using the Keyboard preferences.
set alldisks to paragraphs of (do shell script "df -hlg | awk -F/ '/disk*/ {print $5}'")
try
set item 1 of alldisks to ((characters 1 thru -2 of (path to startup disk as string)) as text)
on error
set alldisks to {((characters 1 thru -2 of (path to startup disk as string)) as text)}
end try
set dur to {}
repeat with m in alldisks
considering case
if m is not in {"MobileBackups"} then
set dur to dur & m
end if
end considering
end repeat
set devnames to paragraphs of (do shell script "df -k | awk -F/ '/disk*/ {print $3}'")
set t to {}
repeat with s in devnames
set t to t & (word 1 of s)
end repeat
set the keylist to dur
set the foundDisks to t
set answer_list to {}
repeat with the_answer in keylist
set theIndex to my CollectUniqueItemIndex(keylist, (the_answer as string))
set theValue to item theIndex of foundDisks
activate
--set answer_list to answer_list & return & ((the_answer & ":" & space & theValue) as string)
--set answer_list to answer_list & ((the_answer & ":" & space & theValue) as string)
set answer_list to answer_list & (the_answer as string)
end repeat
set your_selected_device_id to choose from list answer_list with prompt "Please choose one or more volumes to be unmounted." with multiple selections allowed
repeat with b in your_selected_device_id
set theIndex to my CollectUniqueItemIndex(answer_list, (b as string))
set theValue to item theIndex of foundDisks
--display dialog "The device name of a volume you selected is:" & space & "\"" & theValue & "\"." & space & "Are you sure you want to unmount it?"
try
do shell script "diskutil unmount /dev/" & theValue
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try
end repeat
on CollectUniqueItemIndex(theList, theItem) -- the Item can be string, number, constant, app object or list
local aListMember
repeat with i from 1 to (count theList)
set aListMember to item i of theList
if aListMember = theItem then
set theIndex to i
exit repeat
end if
end repeat
return theIndex
end CollectUniqueItemIndex
[kirkmc adds: This is a very nice script, works as advertised.]
When focus is in the text entry field in an iChat chat window, holding option and using your up and down arrow keys cycles through the previous messages you've sent. This is very similar to how Terminal lets you cycle through previous command just using the up and down arrow keys.
[kirkmc adds: I actually spotted this a while ago. I'm not sure why it's there; and I don't really see any use for it, other than, perhaps, to find a text you sent to someone without scrolling in the window, and then copy it to send to someone else. This works in Lion; can anyone confirm that whether works in earlier versions of OS X or not?]
Apple does not provide any way to count the number of characters in a selected text. Fortunately, you can create your own very easily using Automator.
Launch Automator and create a new Service. Add the Run AppleScript script action, then paste the following code:
on run {input, parameters}
try
set MyText to input as string
set NombreSignes to the number of characters of MyText
set NombreMots to the number of words of MyText
set NombrePara to the number of paragraphs of MyText
set LeResultat to "The selected text contains :" & return & "- " & NombreSignes & " sign(s) ;" & return & "- " & NombreMots & " word(s) ;" & return & "- " & NombrePara & " paragraph(s)."
display dialog LeResultat buttons {"OK"} default button 1 with icon note
on error errmsg number errnum
display dialog errmsg & " [" & errnum & "]" buttons {"OK"} default button 1 with icon stop
end try
return input
end run
Now save the service and use a name such as "Count characters in selection."
To use the service, select any text in a text application (this does not work in Word, however), then choose your service in the contextual menu.
[kirkmc adds: This works as advertised. For some reason, however, when I install the precompiled service, while its name is "Count characters in selection," it displays in the Services menu as "Compteur de signes," which is French for character counter. If you're unfamiliar with using services in OS X, you can see this Macworld article I wrote earlier this year.
My right shoulder had been hurting lately, due to the movement necessary to reach my trackpad. I was using a standard, wired Apple keyboard with the number pad on the right, and my Magic Trackpad was to the right of that, making me reach pretty far to access it.
So, I set out in search of a standalone number pad I could use with my Mac. While I don't work with numbers often, when I do my accounting, it's a pain to have to type numbers from the top row of the keyboard. I looked at a number of models - both wired and wireless - and found what seemed to be the best choice: Logitech's N305. This works with Logitech's Unifying Receiver, is fairly compact, and, according to Logitech, works for three years with a pair of batteries.
But the N305 does not support Macs. Fortunately, in reviews for the product on Amazon, a number of people posted a solution. Download the free KeyRemap4MacBook, a preference pane that lets you remap just about any key on your keyboard or number pad. There is a specific setting in this preference pane for the N305: in the Change KeyPad Key section, you check Logitech N305 hack. The number pad works perfectly, though the top three buttons, which have specific Windows functions (one launches Excel, another the calculator, and a third switches applications).
]Google Chrome keeps older versions of its web browser causing it to balloon in size. I noticed that the Google Chrome App on my Mac was 1.2 GB. That seemed a bit portly for a web browser. Upon looking into the app's bundle, by right-clicking and choosing Show Package Contents, I found multiple old versions of the app, all which appeared to be nearly identical. I removed all but the most recent version and everything appears to run correctly and the app size is now a much more slim 113 MB.
[kirkmc adds: Interesting. On my Mac, in the bundle, in Contents > Versions, there are, indeed, two versions of Chrome. This presumably has something to do with Chrome's silent updating. (Queries on Twitter suggest that this is the norm; a number of people replied that theirs was around 220 MB, as was mine.) Make sure you keep the one with the highest version number. You could also, of course, just download a new copy.
SSHKeychain used to set the SSH_AUTH_SOCK environment variable to something like /tmp/50x/SSHKeychain.socket, but even getting rid of SSHKeychain didn't get rid of the environment setting.
I used to use a great little program called SSHKeychain to maintain my ssh world on OS X. Even after Apple's keychain started dealing with ssh-agent properly, I still kept SSHKeychain around for the convenience of maintaining my ssh tunnel configurations in one place.
However, there was an occasional mismatch between the SSHKeychain way of doing things and the Apple keychain way, and SSHKeychain seemed to have fallen into disrepair, with no maintenance (on SourceForge at least) since 2007.
A few months back, I finally got rid of SSHKeychain, and started having problems.
There was apparently a phase-of-the-moon dependent race condition (somewhere) that clobbered the Apple keychain setting of SSH_AUTH_SOCK with a setting left over from SSHKeychain. This manifested itself as an occasional (during about 50% of my logins to my OS X account) demand for me to enter my ssh passphrase every time I made an ssh connection somewhere else. This, of course, kind of defeats the whole purpose of using ssh-agent in the first place, and was a major pain as well.
I looked at everything I could think of (e.g. .profile et al.) that was related to the problem to no avail. Spotlight was no help in locating the where the variable was being set from. Finally, yesterday, I decided that enough was enough, and ran a find|grep chain over what I thought was my entire disk. There were a few hits (including one in /private/var/vm/sleepimage that seemed like it could have been causing the problem) but getting rid of those still didn't do the trick.
I finally stumbled upon a useful magic search phrase for the problem in Google, and found this discussion from 2007.
It turns out that the culprit was the file ~/.macosx/environment.plist which appears to only have set that one environment variable. Getting rid of that file got rid of the intermittent clobbering of the SSH_AUTH_SOCK variable, and allowed the Apple keychain to maintain access to ssh-agent in the modern fashion.
Woot.
As an aside, I apparently did not construct my find command (in the find|grep chain that I mentioned above) in a way that allowed it to descend into directories starting with a '.' and my brute force search missed the culprit.
I hope this helps someone else avoid all of the blood, sweat, and tears I expended on the problem.
[kirkmc adds: As obscure as this is, we all know what it's like to search for an uncommon problem and not find it. Every problem of this type that is documented helps others in the future when they search for a response.
It's time for a new poll. Following Apple's quarterly earnings call, where the company announced selling 4 million Macs in the last quarter (see Macworld's discussion of Apple's earnings), this could be a good time to find out which model Mac OS X Hints readers prefer. Will it turn out that laptops are popular with readers of this site? They represent 70% of Apple's sales. Or is the Mac Pro still a favorite?
You can vote in the poll, and feel free to post comments on that page about why you selected a specific model.
All those many different WordPress plugins to back up my blog looked too daunting to me, so I decided to create my own simple Mac-native solution using AppleScript. This AppleScript does the following:
Simulates a double-click on the alias to my web server (where my WordPress blog lives) to mount it as a WebDAV volume (just like iDisk)
Runs the handy Unix backup command rsync to copy the remote contents locally
Unmounts my web server
I then set up a daily iCal event to run the script at 4 a.m. Since I already have CrashPlan backing up my hard drive, that takes care of archiving periodic versions of the backup, just in case.
Here's the script:
set filepath to "Macintosh HD:Users:USERNAME:Library:Favorites:www.example.com"
tell application "Finder" to open filepath
delay 30
do shell script "rsync -av /Volumes/www.example.com/blog/ '/Volumes/Backup/wordpress-backup'"
tell application "Finder" to eject "www.example.com"
Set you own user name, domain and backup destination in the script.
It's also worth pointing out that while there are many WordPress backup plug-ins available, it is also a good idea to use one. The backup in this hint only backs up files, not the actual WordPress database. I use the WP-DBManager plug-in for automatic backups of my database, that are sent to me by e-mail.]
You know how when you want to change a file extension in the Finder, you get a warning asking if you're sure you want to change the extension? In most cases, if you are changing the extension, you are doing so because you want to, and you know the consequences.
You can disable this warning. Run the following command in Terminal: