For a long time I've really liked that you can drag files from the finder (or elsewhere) to a Terminal window, where they appear as a path. Unfortunately, there has never been a nice way to drag from the Terminal. For example, if I have a new tarball that I want to send someone, I have to click Attach in Mail, and then find the file using the Open sheet.
I've just written a program -- Drag.app -- that does allow you to drag from Terminal, and it is available for free, with source. It adds a new command (shell script), drag , which is usable from Terminal. When executed, it opens a new window with a file icon that can be dragged as normal. When the drag is complete, the app quits so your desktop isn't cluttered and you can get back to the command line.
The closest I've seen to this before is the open command. If you open the enclosing directory of a file, then it will be displayed in the Finder -- you can find and drag a file from there. That approach has the downside that you'll sometimes get a .DS_Store file, and it can still be hard to find the file you want if the directory has a lot of files in it. My command cuts to the chase and lets you drag the file(s) you want, then gets out of your way.
[robg adds: I tried this, and it worked well. The download includes a compiled Intel Mac version; you'll have to compile your own for PowerPC, and that's left as an exercise to the reader...]
I wanted to use the QuickTime "Image Sequence" feature to make rapid MPG movie out of a folder of JPGs. The problem was there were 600 pictures taken with my iSight over seven months, so I used a simple perl script to bulk-rename the files (it actually uses cp, so your original files are untouched). After running the script, open QuickTime, choose File » Open Image Sequence, and select 1.jpg, then the frame rate, etc. Here's an example of the finished product. (I used the iSight auto-capture hint I submitted earlier this year.)
I am sure some of you have had this issue before if you use more than one platform at home. Personally for me, OS X and iTunes lack some audio features I like so I don't do my audio ripping from my personal CD collection on a Mac. I do it on my windows/Linux box so I can take advantage of some good open source formats like OGG, FLAC, and MP3vbr (though I think the newest release of itunes will support VBR? not sure). [Editor: iTunes has had VBR support for quite a while.] However, I like to have my music collection on my Mac so I can listen to my music when I am working on it, and my laptop is a Macbook Pro.
I am sure a lot of you already know this, and this is nothing new or exciting, but I have used basic Unix commands to copy my music directory from my PC to my Mac using rsync, and have not had it copy over any duplicate albums. For example, I have about 40GB of music ripped to my PC of my own personal collection. When I copy it via SMB over the network, it duplicates about every five albums or so which is annoying. To get around this I simply used rsync instead. Make sure all the proper permissions are in place, so you can mount your share from Windows or Linux box on your mac. Connect to the share and mount it. Once it's mounted, use this very simple command:
You can use this over and over again -- the -u tag should only copy new material from your other computer and not copy what has already been copied. I have been using this method for about a month now, since I rip everything in FLAC then convert it to MP3 and then copy it to my Mac via Terminal. So far no more duplicate albums are being copied using this method.
Also since you can simply drag and drop the file paths directly into Terminal, it makes it even easier. If you were so inclined, you could make a shell script doing this with a cron job so it auto-updates once a week or whatever. This method could be applied from Mac to Mac as well, but if your Macs are networked, you could just share it over AirTunes or what not.
This excellent tip explained how to manage LPR printers using the command line lpadmin printing tool, but there were no instructions on how use printer queues for high-end printers with a RIP -- like those from Xerox and Canon. Typically, these printer queues will contain options such as Print, Hold or Direct. Although it's easiest to use Open Directory to manage your printers and these special settings, if you use ARD or Filewave for Desktop management, you can issue a shell command or shell script to automatically add these special type of printers without end-user disruption.
Simply add your printer's queue to the end of the IP address or URL like the example shell script below, and voila, your users will have all of their special printer configurations added automagically.
#This script installs the left and right Xerox printers in Imaging
lpadmin -p Left242 -L "Left Xerox 242" -E -v lpd://left242.yourdomainorIPaddress.com/PRINT -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Fiery EX260 Color Server PS.gz"
Recently, someone asked me how they could use Skim as his TeXShop previewer. That is, he really liked Skim and wanted to be able to use its PDFSync support to bring up a line of TeX source inside TeXShop. So I put together a shell script that mainly consists of the following:
If you save this script as texshop in your PATH (e.g, as /usr/local/bin/texshop) and chmod it 0755 (e.g., chmod 0755 /usr/local/bin/texshop), then you can go into the Skim LaTeX preferences and set the Preset to Custom, with the Command set to texshop, and the Arguments set to "%file" %line. I hope some other people find this useful
After reading a lot of things about the issue of non-saving history files after session closing in tcsh (my favourite shell, especially for its completion flexibility), I founded that putting these lines...
set history = 2000 # History remembered is 2000
set savehist = (2000 merge) # Save and merge with existing saved
set histfile = ~/.tcsh_history
...in .tcshrc and this line...
...in .logout solved the problem. Now history is not only preserved between Terminal sessions, but also merged (considering command dates). Also, it is not necessary to issue an exit command, but with a normal window close, the current history is merged.
[robg adds:This older hint covered savehist, but it seems you still had to use exit to get everything to work. The above solution should also work if you simply close a Terminal window.]
I have read all the hints about command line calculators, and I've tried just about all of them, including:
Unfortunately, none of these options had built-in functions like sin() or cos(), or constants like pi. For Python, in order to include the math library you have to type from math import *. But then to get it to do the things you want (like adjusting precision), you have to be familiar with Python and/or you have to read documentation on the Python math library. The problem with bc is that when you type bc -l you only get six built-in functions, such as s(), c(), a(), which are sine, cosine, and arctangent respectively. You don't get any built-in constants.
There's a better way, but it requires a small download of a program called wcalc. If you have Fink installed, you can just type fink install wcalc (or get the pre-compiled version via sudo apt-get install wcalc. After you've installed wcalc, on the command-line in Terminal, type wcalc and you're set to go. The program provides you with a prompt and tells you "Enter an expression to evaluate, q to quit, or ? for help." It's pretty self-explanatory.
[robg adds: The Fink version of wcalc is 1.7. However, on the home page I linked above, you can download version 2.2.2 for Mac OS X, which also includes a GUI version.]
Showing the latest job in each window title is my preferred way to tell multiple Terminals apart. Unfortunately the GUI method is rather useless (File » Set Title... » Active Process Name will make most windows say bash), and this old hint only covered tcsh. To update it, here is (in a nutshell) the command to issue, or to put in the appropriate startup file:
While the how-to cited in the old hint did contain the zsh and tcsh methods, and while in retrospect the ksh trap '...' DEBUG method had been working since long before, the idea of using it for the present purpose seems newer and due to Paul Jarc, who first mentioned it shortly after bash switched to the ksh93 standard of running '...'before (rather than after) each interactive command. (Prior to that, the effect was reputedly impossible to obtain without recompiling bash.)
Lately zsh (≥ 4.3.3) also rescheduled the trap, so recent versions also support Jarc's method -- provided you preface it with set -o debugbeforecmd.
After finally getting tired of remembering to "Empty Trash" at regular intervals, I decided to write a script (36KB download; source code on macosxhints) that automatically cleans files out of the trash after they've been there for seven days. It will even use sudo to clean out things that I don't have permission to erase -- if that option is available. There are many options to choose from, just use --help to see them all.
This script is designed to be very efficient to run, so I run it hourly. There is not (yet) any provision for maintaining the Trash at a particular size. I recommend adding a line to your cron file like this:
@hourly python /your/path/to/dirscan.py
This will clean things out after a week, and checks each hour for new items to remove. It pays attention only to top-level entries within .Trash, so any directories you put in the trash will be deleted automatically.
[robg adds: The code download link is from the author's site, and will be the best place to grab the latest version of the script. I mirrored the source as of today on macosxhints.com, just in case the parent site goes away at some point. Note that I haven't tested this one. Finally, for those interested in a size-limited trash can, this hint and the associated comments offer a few solutions.]