Sometimes you may need to get a sorted list of all files in a direcoty transformed in a database format, so, after getting the directory list you may end cutting and pasting the data to your database. On the other hand, there's an easy way to do that, if you just follow this tip. Open Terminal and type:
If you want to generate a file instead of sending the result to the clipboard, just replace the | pbcopy part with > xxx, where xxx is the file name you want to create.
[robg adds: When this hint was submitted, Geeklog killed the backslashes in the above command. After much trial and error, I believe I have them back where they need to be to generate the proper output. If there are errors, however, they are mine, not the original poster's. I also split the command onto three lines for a narrower display, but it should copy and paste.]
As an owner of two iBooks and a Mac mini, it has struck me that these are all likely targets for a thief. A while ago I recalled this story about how someone used Timbuktu Pro to recover a stolen iMac. I then realised that because we use Apple's Remote Desktop software at work, then all I need is the current IP address of a computer to be able to observe/control it.
So I wrote a perl script to lookup my computer's IP address and email it to me at regular intervals. I then had the idea to make the script determine the location of the computer based on the IP address. This is not always an exact science, but it can often pinpoint the town where the computer is. Recently I also realised that I could use the UNIX screencapture command to also email myself a screen capture (to potentially see what any thief is viewing/typing). This might be of more use to those who don't own Remote Desktop. Finally, my latest source of inspiration occurred after buying an iSight camera for my Mac mini. I discovered the great (and free) isightcapture utility, which now allows me to email pictures taken by the iSight camera.
So I now have my computers send me regular emails throughout the day which get automatically filtered by a rule in my Mail application. Because each of these three different functions (IP address, screen capture, and isight capture) require different tweaks to the system, I wrote three different perl scripts so people can pick and choose what functionality they want. These three scripts can be downloaded as a tarball, or downloaded separately from my blog, which has full and detailed instructions on how to install each script (some require some tweaks to the system).
The main limitations of these scripts are that a) the stolen computers need to be online long enough for the scripts to run, and b) the thief doesn't just wipe your hard drive. I try to counter the second option by not using a password on the screensaver, and setting the computers to automatically log into a somewhat-restricted guest account following any reboot. Hopefully this would encourage someone to use the computer just long enough for you to get some helpful information emailed to you.
The Remote Desktop Client app is a pretty handy way to remotely manage/control a Microsoft Windows workstation. However, the solution Microsoft provided is a little bit outdated and runs on Rosetta, which hogs CPU and memory. An alternative way of doing this is by using the rdesktop program, which is open source for Linux/Unix.
First, go to their download page and download the latest source code. Extract the source to say ~/rdesktop. Then, we need to compile the program on Mac OS X. Open Terminal and cd ~/rdesktop, run the following commands:
$ sudo make install
Finally, you can use X11 to run the rdesktop program.
[robg adds: You'll need to have the X11 application installed in order to compile and use rdesktop. I had some issues initially, due to an X11 install that was somehow messed up (no X11R6 directory in /usr). After some retries with the X11 installer, compiling worked as described above.]
As a Mac OS X administrator and as someone who likes to use shell and perl scripts to automate things, I find myself doing a lot of debugging and logging. To make things simpler, I wrote a perl script which I call from other scripts to output errors, warnings, and info in an ordered, easy-to-read system-log-like format.
Save the script text to a file (logger.pl), open Terminal and change the file mode to allow execution (chmod u+x /path/to/logger.pl), and call the script within (or without) another a script like this:
The process list of Activity Monitor is very nice, but oftentimes I want a lightweight alternative that is easy to start, and has very little impact on system resources. In order to achive this goal, I started with the top command as my basis. In its standard mode, top is still a bit resource hungry, so I added a few options (remove costly traversals of kernel datastructures, update every 10 seconds, sort by resident memory size):
/usr/bin/top -R -F -s 10 -o rsize
For making this command easily usable (either by double-click or by Spotlight opening), I used the Execute this command feature (Execute command in a shell activated) with the exec command at the beginning of the above command line in the Save dialog of Terminal. Together with setting the Close the window option in Window Settings... > Shell, this ensures that very little memory is consumed (the shell is replaced by using exec). The resulting Terminal window containing top can be easiy terminated by just typing q when it is active. Additionally, the scrollback buffer should be disabled in Window Settings... > Buffer.
Saving the resulting file under the name topmem.term makes it possible to either double-click the file, or start it by typing topmem in Spotlight and hitting Command-Return. Additional commands can be built, which sort by different fields (e.g. -o cpu, -o time). I have put a ready-made topmem.term as shown above (with green on black colors and slight background transparency) on my website.
[robg adds: I haven't tried the linked topmem.term file, but the rest works as described.]
The great and free GeekTool (PowerPC | Intel) can write the contents of any file, and the output of any shell command, right onto the desktop. Unfortunately it doesn't support self-updating commands like top, and the official workaround (break the loop with top -lk and set Refresh to keep restarting it) is rather Heisenbuggy:
With k > 1, they become skewed by an overestimated CPU usage for top itself.
Either way, relaunching top every few seconds soon causes pid's to roll over 30000, so that recent processes must be hunted down the list rather than conveniently appearing on top.
In short, watching top this way perturbs it more than we'd like. In this hint, I describe a different (k = 0) workaround which appears to solve the problem, i.e. display top exactly like Terminal does.
Looking through applications in Terminal, I stumbled upon automator, which simply lets you run an existing Automator workflow from the Terminal. This could be useful in Perl, Bash, and other scripting.
[robg adds: The man page for the command is quite brief; it says just this: automator runs the specified workflow document. To create or edit a workflow, use the Automator application. There are no options.]
This hint allows you to randomize your e-mail signatures. I use this with Thunderbird, but this hint should work with any e-mail client that refers to an external file for your signature. I needed a solution that just worked and didn't really require anything more from me. Some of the plug-ins out there require some user action each time you write an e-mail -- which I didn't like. Also, most of my signature remains the same, so I wanted my solution to simply change one part of my signature (a tagline), the rest remains the same.
Basically, my solution is composed of a couple files which can be merged to form a random signature (and any supporting graphic files, etc). These should be placed in your normal directory holding your signature. For this example, let's say this is the directory /Users -> jbloggs -> signature/:
signature-template.html - my normal signature (and all of its support files), but with a minor change: I've replaced the tagline with a marker [TAGLINE].
taglines.txt - this is a list of all my taglines that I want to randomly choose from for each e-mail. There is one tagline per line, and any characters that might be special to the shell must be escaped properly.
Other files required to make up this solution are the following, which are to be placed in the directory /Library -> StartupItems -> SignatureRandomizer, which is owned by root, has its group set to wheel and has permissions 0755 (drwxr-xr-x):
SignatureRandomizer.watchdog - this is the magical bit. This shell script monitors my signature.html file to see if it has been used, and if it has, it creates another one by randomly selecting a line from my taglines.txt file and inserts it into the signature-template.html file.
SignatureRandomizer - this script controls the watchdog-script.
StartupParameters.plist - this is required to automatically start the service when my Mac boots up.