blog :: en :: computers :: mac
Autograce is a simple AppleScript to change the grace period of your screensaver automatically, depending on the BSSID of your current WLAN. If you're at home, after the screen saver activates, you've got one hour before having to re-enter your password. If you're away, this time is reduced to five seconds.
For this to work, you will have to enable support for assistive devices in the Universal Access pane of your System Preferences. After download, edit the script to set the BSSID of your home WLAN. Save it as an "Application" and make sure to set the option "Stay Open" so that it will keep monitoring your connection. You can add the script to your startup items to have it open whenever you log in. The script uses the System Preferences application to make changes. To avoid interrupting your work too often, it will only check once in five minutes, and will only change things if necessary.
The script was tested on OS X Lion and will probably not work on other releases of OS X. Say Hi to Apple for working hard to ensure programmers stay in business. ;-)
posted at: 10:52 | path: /en/computers/mac | permalink
I'm no longer using Time Machine for my backups. However, this hint has saved my life once, and I wanted to share it:
Assume you've got an encrypted disk image on your hard disk to store some secret information. While this image is mounted, Time Machine creates a backup. Now you've got a copy of the encrypted disk image on your backup medium, but it's inconsistent and not easily readable.
Apple knows about this problem enough to disable backups of FileVault encrypted home directories (which are nothing more than encrypted disk images) while they're mounted. That's why you get a warning when enabling Time Machine, and have to wait minutes or hours for a backup to be created while you're logging out. However, this safety net is not in place for other disk images.
To read the image, you would have to fsck it, which you can't do while it's on a time machine volume (and thus readonly).
One solution is to mount the backup of the encrypted image with a shadow file where write operations (including those necessary during fsck before the drive can be mounted) can be directed.
Sample command (please remove linebreaks before trying):
hdiutil attach /Volumes/Backupdisk/Backups.backupdb/mymachine/Latest /Macintosh\ HD/Users/Shared/Archives/Secret.sparsebundle -shadow /tmp/test.shadow -autofsck
In this example, /Volumes/Backupdisk is where your Time Machine volume is mounted, mymachine is your computer's name, /Users/Shared/Archives/Secret.sparsebundle is the name of the encrypted disk image, and /tmp/test.shadow is the name of the shadow file (on your regular disk) where write operations go.
posted at: 07:00 | path: /en/computers/mac | permalink
While partitioning a hard drive using Mac OS X 10.6 I encountered strange error messages. Disk Utility complained about non-existing partitions while creating or deleting partitions, irrespective of whether it had been started directly from hard drive or from a boot and installation CD. After creating partitions using GNU parted, the new partitions were visible in Disk Utility, but could not be erased there (same error message). OS X style "mkfs" using
sudo diskutil eraseVolume hfs+ Shared /dev/disk0s5
worked, but mounting the freshly created volume using
diskutil mount Shared
or
sudo mount /dev/disk0s5 /Volumes/Shared
did not, producing error messages about a "bad super block". The volume was not mounted during bootup, either. I could manually mount the volume, though, using
sudo mount_hfs /dev/disk0s5 /Volumes/Shared
fsck_hfs did not produce any error messages.
After much fussing about I found that the root of my problems was my use of configuration-independent volume labels in /etc/fstab.
An old-style fstab line for the fifth partition on the first disk drive might read like this:
/dev/disk0s5 /Volumes/Shared hfs rw,nodev,noexec 1 2
It lists
The problem with this approach is that adding or removing a drive, or replacing the kernel, can change the name of the device node. Thus, /dev/disk0s5 in Darwin 10.6 might be called /dev/sda5 in Linux 2.6, and adding another disk might shift its position to /dev/disk1s5 or /dev/sdb5. These changes might render a perfectly bootable system unbootable.
To overcome this problem, modern unix systems support different notations in place of specifying device nodes. Thus, /dev/disk0s5 might be replaced by things like LABEL=Shared (identifying the partition by a label assigned to it in the partition table or using mkfs) or UUID=B321FECB-F0F0-1112-014C-052341494E21 (identifying the partition by a unique ID assigned to it by mkfs, diskutil or hfs.util). Thus, the line above would read:
LABEL=Shared /Volumes/Shared hfs rw,nodev,noexec 1 2
On first glance, the man page for fstab(5) in OS X seems to suggest that OS X supports this format. This is not however the case for all utilities, and apparently Disk Utility, mount and diskutil are among those utilities that do not support the LABEL=... notation.
Converting my /etc/fstab back to the old-style device nodes solved all mysterious problems.
posted at: 06:40 | path: /en/computers/mac | permalink
When installing software using MacPorts, the system downloads the current source code, compiles and installs it. It does so automatically for the software you request, but also for all "dependencies", i.e. software that is required to run or install the package you want.
This is very practical, but it can take a while, especially if you're trying to install a large and complex package. And the time it takes is composed of alternatively downloading the next bit of software and installing it. While the computer is downloading something, the processor sits idle, and while an install is running, no download is happening. Would it not be more time efficient to download the next archive file while installing the current one?
While MacPorts will not do this automatically (yet?), the recent update to 1.9.0 allows you to do it manually.
Say you want to install octave. Open two terminal windows.
In the first one, you start the installation itself:
sudo port install octave
It will compute dependencies, then start downloading the first package to be installed.
In the second window, as soon as that first download running in the first window has completed, start the download for all other packages required:
sudo port fetch rdepof:octave octave
This is still far from perfect, since rdepof: will download dependencies in alphabetical order, while port install requires them in order of dependencies, i.e. it can only install a package once all dependencies for that package are there. This means that the install process will still download some packages at first.
Also, MacPorts uses locking to avoid more than one process working on the same port at the same time. This means that port fetch can stall downloading if it encounters a port that port install is currently working on, but it will continue afterwards.
MacPorts 1.9.0 also supports port rdeps octave, which will list the dependencies for octave in hierarchical order, which could be used to download them in the correct order. This is left as an exercise for the reader. ;-)
posted at: 15:46 | path: /en/computers/mac | permalink
Here are some useful hints around sleep and wake (suspend and resume) in OS X.
"Sleep" and "wake" are Apple vocabulary for the more common "suspend" and "resume".
Closing the clamshell lid will automatically sleep (suspend or even hibernate, depending on power management settings) an Apple laptop (iBook, MacBook, MacBook Pro). Apparently, this cannot be prevented using on-board means. With recent devices, operation with closed clamshell is possible, with external periphery connected (typical use: external monitor, keyboard, mouse). However, the computer will still go to sleep once the lid is closed, and will have to be woken again. Apple calls this "closed clamshell mode". See this apple knowledge base article for details.
InsomniaX is a tool that can prevent the laptop going to sleep on clamshell close, even if no external devices are connected.
Normally, the computer will automatically wake (resume operation) when the clamshell lid is opened again. This is controlled by standard power management and can be tuned using pmset. The command sudo pmset -b lidwake 0, for example, will prevent automatic wake on lid opening if the computer is currently on battery. You will have to press a key to wake it.
SleepWatcher is a little daemon that can run shell scripts before sleep (suspend) or after wake (resume).
posted at: 17:21 | path: /en/computers/mac | permalink
Yesterday, Apple released 10.4.3. But the best improvements are not even listed in the official release note, only in some obscure readme:
X11 windows are no longer hidden after switching applications! This was an ugly bug, especially since most X applications require you to turn off command keys— after all, you need the command key to act as a modifier. Previously, any application windows used to be hidden after switching back to X11. You had to use the mouse to manually bring them forward again. Which might be okay for mouse users, but which is terrible for keyboard enthusiasts.
And: FAT formatted volumes perform much faster. Finally, it's possible to carry an encrypted disk image on a FAT formatted USB stick—meaning you can use the same stick to transfer data from and to your mac.
I'd say "great work" if it wasn't for the fact that these are long-standing and annoying bugs! ;) But they're finally fixed, and that's certainly good.
posted at: 16:31 | path: /en/computers/mac | permalink
I just downloaded iTunes 6 via Apple's Software Update. I'm not very impressed with what it offers.
Video downloads are EUR 2.49 – I hear the U.S. version is asking only USD 1.99 or EUR 1.64 per download. That seems like a hefty fine for being European. But then you see a download (I've only actually seen the previews), and they are tiny! Possibly in keeping with the small screen size of the new iPod, but why on earth would I pay 2.49 Euros for a video that is not much larger than a stamp? Huh.
They're also promising TV series, which do not seem to have made it to the German store yet. Assuming a price of 2.49 per episode: Who's going to pay that much? A complete season of Friends on DVD, for example, is 20 Euros for 24 episodes or 83 Cents per episode – and it is acceptable quality even on full screen. Why pay three times as much for a stamp-sized version?
posted at: 00:21 | path: /en/computers/mac | permalink