Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Sort files into date-labeled subfolders using Perl UNIX
When I installed Leopard, I installed it to an empty partition using a clean install. I then manually migrate my older documents and settings over time -- it's not that I don't trust the Migration Assistant (well, I don't trust it completely, but that's another story), but that I look on each major OS X upgrade as the chance to clean house. So this weekend, after a slow migration, I decided it was finally time to zero out the old 10.4 partition ... but I had a slight problem.

I archive my iChats, and have done so for many years. In those archives, there's a ton of knowledge that I prefer to keep rather than lose, so I wanted to move the archived chats into my current iChats folder on the 10.5 disk. In 10.4, all iChat archives were stored at the top level of your user's Documents » iChats folder. In 10.5, however, archived chats are now sorted into subfolders based on the date of the chat. I wanted to move my huge archive to the 10.5 partition, but I didn't want to clutter the archives folder with thousands of files at the top level -- I wanted them sorted by date, as in 10.5.

I was pretty sure that Perl could make short work of this problem ... if only I knew Perl. Thankfully, I know someone who knows Perl; you might even say he wrote the book on it. Randal Schwartz (aka merlyn here on macosxhints.com) came to my rescue with a nifty bit of code he cobbled together while waiting for a flight.
read more (302 words)   Post a comment  •  Comments (5)  
  • Currently 1.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[12,855 views] Email Article To a Friend View Printable Version
Add an Insert key in Terminal and X11's xterm UNIX
I need an insert key to work with my company's custom software, not to mention all the little annoying little Unix programs that expect a INS key. With X11 apps, its easy to use xmodmap f12 to temporarily emulate an insert key. Just type the following in xterm:
xmodmap -e "keycode 119 = Insert"
Now the F12 key acts like insert in all X11 apps, as long as you run them from the terminal. The best part is that keyboard settings go back to normal as soon as you close the Terminal, so you don't have to worry about changing it back. That's all well and good, but I prefer to use the Mac's Terminal.app when possible. Fortunately it's pretty easy to emulate an INS key there, too. In Terminal.app's Preferences, go to Settings and select Keyboard. Find the Key you want to replace -- in my case, F12 -- and change the default Action value to:
\033[2~
Note that the \033 is the Escape key, not those literal characters. I haven't been able to find a way to easily revert the setting, but I don't tend to need the F12 key in the Terminal, so I just leave it.

[robg adds: As submitted, the hint contained the actual key sequence and instructions to copy and paste it into Terminal. However, between Geeklog submission and publication, something munged the string, so I had to remove it. Theoretically, you should be able to type Escape followed by [2~ and make this work. However, I created the sequence by editing the existing definition for F12 (double-click it), as it ends in 24~. In the edit box, there's a Delete One Character button, so I clicked the mouse to the right of the 4, then clicked the button to delete one character. However, I'm unsure about testing the functionality of this keystroke, as I rarely use X11 apps.]
  Post a comment  •  Comments (2)  
  • Currently 2.71 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (7 votes cast)
 
[24,426 views] Email Article To a Friend View Printable Version
Download files from web servers via ftp program UNIX
The command line BSD ftp utility that ships with OS X can be used to download files via HTTP as well as FTP. For example, in Terminal, you would do this to download a DMG file from some site:
$ cd ~/Downloads
$ ftp http://www.some_site.net/file.dmg
You will see the file automatically begin downloading into your current directory, which you set to your Downloads folder with the first command. Now you probably won't need to install the GNU wget utility.

[robg adds: Note that OS X also ships with curl installed, which can do the same thing and much more (man ftp and man curl for more on both these apps, of course.) To grab the same file with curl, you'd use curl -O file.dmg.]
  Post a comment  •  Comments (6)  
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[10,721 views] Email Article To a Friend View Printable Version
Clear msftres and other GPT 'flags' set by GNU parted UNIX
This hint most likely only applies to people who have installed or used Linux on an Intel-based Mac. If this is not you, you may want to stop reading now.

Anyway, if you have tried to edit a GPT partition map using GNU parted, or a utility that uses libparted, and if you're not very good about following directions (like me), you may have accidentally set some of the partition "flags" that it exposes, such as msftres or boot. I put the term "flags" in quotes because it appears that parted actually changes the partition's type in the GPT from whatever it was before to -- in the case of msftres -- a "Microsoft Reserved" partition (GUID E3C9E316-0B5C-4DB8-817D-F92DF00215AE). These can have some unintended consequences -- as I found out, setting boot on any partition besides the EFI reserved one at the beginning of the disk will make any OS X installations on that disk unbootable.

Fortunately, boot can be easily unset the same way you set it (using parted). But, when you do so, at least using the version of parted that comes with Ubuntu Gutsy, the msftres flag is set, and parted won't let you unset it no matter how many times you try. The main problem this caused for me was that the partitions marked as msftres would no longer be mounted automatically by OS X, so they didn't show up in the Finder, and they were grayed out in Disk Utility. diskutil list indeed showed their type as "Microsoft Reserved Data" or something to that effect. (I don't remember exactly, and I didn't feel like changing the type back just to do testing for this hint.)

But -- and here's the hint -- it turns out that Disk Utility will still let you (try to) mount the partition, even though it's grayed out! Just select the partition and click Mount in the toolbar. If the filesystem is one that OS X recognizes (including FAT32 or NTFS), the volume will mount successfully and you can use it in OS X once again. What's more, as you can confirm using gpt or another utility, Disk Utility rewrites the partition map for you, back to the way it should be. (Although I don't know whether it does this on mount or when you later unmount the partition(s) in question, e.g. the next time you shut down OS X). At that point, everything is good as new.

I hope this helps someone out there; much anxious Googling didn't reveal anyone else who had figured out how to unset msftres.
  Post a comment  •  Comments (13)  
  • Currently 2.14 / 5
  You rated: 2 / 5 (7 votes cast)
 
[37,134 views] Email Article To a Friend View Printable Version
10.5: Control MySQL server with launchd UNIX
I recently installed a copy of the MySQL database server on my Leopard machine. The MySQL site offers a packaged version of MySQL 5.0.x for OS X 10.4 on their downloads page (current as of this posting: 5.0.51).

This 10.4 version works perfectly well with 10.5, except for some minor inconveniences. The first is that they include a preference pane for System Preferences, which doesn't work. They also offer to install a StartupItem to start the database server during boot. This works pretty well, except that Apple has marked StartupItems as depreciated since 10.4, noting that you should use launchd instead. There are many hints out there to create a launchd job using the MySQL supplied launchd_safe, which is basically a shell script for starting, monitoring, and restarting mysqld. That's a pretty ugly solution to start a server with launchd, and is actually discouraged by Apple.

So this hint is about replacing the StartupItem and the mysqld_safe script with a simple launchd job. It assumes you are familiar with the Terminal, logged with an administrator account, and have basic knowledge of launchctl and launchd.plist files. Also being familiar with MySQL configuration might help.
read more (450 words)   Post a comment  •  Comments (18)  
  • Currently 2.88 / 5
  You rated: 3 / 5 (8 votes cast)
 
[43,570 views] Email Article To a Friend View Printable Version
Ease shell operations using a spreadsheet UNIX
Diehard Unix gurus are going to be shocked to see Excel and the Unix shell mentioned in the same hint. Yet this can prove a very powerful combination for the average user. Unix gurus should read on, too. Say you want to remove a bunch of files from different locations in your file system, for instance, temporary files. The Unix way of doing things would be:
find -name "*~" -exec rm {} ;
We are doing nothing special here: find by name and then remove. Yet this bit of shell may be above the skill or the courage of many Mac users. In real life, you may want to do more complex searches (by modification date, in multiple locations, file type, ...), or do more complex operations (copy, rename, ...). You will quickly find yourself in need of a full-blown shell script which loops over the results from mdfind. Well, there is an easier solution involving HoudahSpot and your favorite spreadsheet (Numbers, Excel,...).

First, use HoudahSpot to formulate a query matching your files. You may create arbitrarily complex searches by combining criteria using boolean operators. You may search several locations at once, yet exclude others. Once you are satisfied with the result, configure HoudahSpot to show the file path column for the result list. (Control-click on the column headers in the results area, and select File Path from the pop-up menu.)
read more (294 words)   Post a comment  •  Comments (5)  
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[6,208 views] Email Article To a Friend View Printable Version
Bandwidth throttling in OS X UNIX
Advanced OS X users know that Darwin comes with ipfw, which can be used to set up a custom firewall. This same service however can be used to also limit bandwidth on specific ports.

Example:
sudo ipfw pipe 1 config bw 15KByte/s
creates a pipe that only allows up to 15KB/s to go through.

Then:
sudo ipfw add 1 pipe 1 src-port 80
will attach that pipe to the outgoing traffic on port 80, effectively limiting the outgoing traffic of the web server.
sudo ipfw delete 1
will remove the pipe from the port.

[kirkmc adds: I haven't tested this. Just make sure you remember to turn this off when you no longer need it!]
  Post a comment  •  Comments (18)  
  • Currently 4.46 / 5
  You rated: 5 / 5 (13 votes cast)
 
[123,029 views] Email Article To a Friend View Printable Version
10.5: Fix a broken Gnu M4 in 10.5 UNIX
Leopard ships with an older version (1.4.6) of Gnu M4, the macro programming language used mostly by Gnu Autotools. You might therefore get this error when trying to build a configure script:
/usr/bin/gm4: INTERNAL ERROR: recursive push_string!
autom4te: /usr/bin/gm4 failed with exit status: 1
Once you learn that this is a well-documented bug in m4 1.4.6, you'll immediately go to the Gnu M4 Downloads page and retrieve the latest version. However, version 1.4.10 seems to have a bug which makes it fail to write most of the output on OS X 10.5 (even though it works fine on Linux). Instead, get 1.4.9, and all will be well.

Note that this problem is only going to affect people writing autotools build scripts, or building sendmail.cf files, or otherwise using M4. It has no effect on, for example, running configure to build a project you got from somewhere else.
  Post a comment  •  Comments (0)  
  • Currently 3.67 / 5
  You rated: 5 / 5 (6 votes cast)
 
[8,392 views] Email Article To a Friend View Printable Version
Use pseudo terminals as named pipes in Finder UNIX
I am currently using VLC for my streaming radio fix. As VLC does not update its track and title information, the are three ways for me to check the current streaming radio track. The first two are to Get info on the current stream in VLC, or use VLC's embedded message viewer, both of which require a lot of mousing around, aren't a quick view solution, and neither allow me to constantly see the changing track names.

The other is to write the message viewer's contents to a log. I was using a standard log file, but after constantly having to erase the file after it became too big, I realized that this going to kill the hard drive in no time, especially if I do the same thing on a flash-drive-based linux distro (Which I am planning).

After digging, I found out about FIFOs and named pipes, even seeing a hint here about them. I also read about how the GUI side of OS X does not handle named pipes graciously (Finder or VLC crashes). But reading around, I noticed pseudo terminals and had an epiphany. GUI apps can access /dev devices (such as sound cards and serial ports) by name, so why can't they write to them?

I end up assigning VLC to log to /dev/ttyu1 then I cat /dev/ptyu1. tail does not work on /dev/ptyu1 because the pseudo-terminal does not have an for it to work from, and cat keeps reading until it receives one (when VLC quits). This way, VLC in the GUI thinks I am logging to a file, and I can see what is being logged (via Terminal) without actually writing the log to the hard drive.
read more (192 words)   Post a comment  •  Comments (2)  
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[7,651 views] Email Article To a Friend View Printable Version
Speak the time on the hour via Terminal UNIX
Some may be familiar the say command, where you simply open the terminal and type say (something) and your mac will speak. This is especially fun when you are logged in remotely via ssh, and someone is close to your mac at home.

Anyhow, by combining the say and date commands, you can then set up a cron job that will allow your Mac to speak the time at any interval you choose. I'm not sure if there are utilities out there that can do this, but this is certainly a good way learn how to use some of the Unix goodness in OS X.

[robg adds: You can set up a voice announcement on the Clock tab of the Date & Time System Preferences panel -- at least on the hour, half-hour, or quarter hour. Read on, however, if you're new to the Unix side of OS X and you're interested in learning a bit more about it. This solution also has the advantage of running for all users, not just for the logged-in user.]
read more (379 words)   Post a comment  •  Comments (9)  
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[11,825 views] Email Article To a Friend View Printable Version