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

Convert Clipboard contents to plain text UNIX
There was a recent article on the Macworld main site about apps you can buy that will strip formatting from text on the clipboard, leaving you with plain text that you can paste into documents without it having the wrong font, etc.

Although some of them do this automatically, I thought it's a bit much to pay for such a simple utility that can be done in one line on the CLI.

So here's a shell script that will convert the contents of the clipboard to plain text.
#!/bin/bash
#
# Convert contents of clipboard to plain text.

pbpaste | textutil -convert txt -stdin -stdout -encoding 30 | pbcopy

exit 0
The encoding option specifies MacRoman (30). I find that the default, UTF-8 doesn't always cope well with things like curly quotes.

If you have the AppleScript script menulet active, you can store the script in /Library/Scripts, and you can select it from the menu. It will run without opening the Terminal, as per this hint.

[crarko adds: This seems to work as described; I had to run the script twice before it did though.]
  Post a comment  •  Comments (15)  
  • Currently 3.64 / 5
  You rated: 3 / 5 (11 votes cast)
 
[7,777 views]  View Printable Version
Compress all the PNG files in your Home directory UNIX
PNG image files are often not compressed with the optimal compression setting, however a one line command can fix this (and save some space).

Basically, one just needs to have MacPorts and the optipng port installed, and run the following command:
mdfind -0 -onlyin ~ "kMDItemContentType=public.png" | xargs -n 5 -0 optipng -preserve
For more details, see this blog entry.

[crarko adds: I haven't tested this one. Note that to use MacPorts you also need to have Xcode installed to compile the ports. If you already have MacPorts set up give this hint a try and let us know how efficient the compression is for you.]
  Post a comment  •  Comments (3)  
  • Currently 2.17 / 5
  You rated: 4 / 5 (6 votes cast)
 
[4,184 views]  View Printable Version
Try the GIMP version 2.7.3 in OS X UNIX
In a previous hint, I suggested to install the development version of the GIMP (which also has the new, well-known single window mode) in an Ubuntu virtual machine: which obviously wasn't an optimal solution.

Now, there is another option: install the GIMP 2.7.3 via MacPorts; here's how to do it.

First of all, if you don't have it yet, you need to install MacPorts, available from here.

It is always a good thing to do a selfupdate; in the Terminal type:

$ sudo port selfupdate

Now, we can install the GIMP's development version (currently available in version 2.7.3):

$ sudo port install gimp2-devel

There are also many, many dependencies, and thus many packages to compile form source, so you must be patient; it can take several hours (for me, on a 2010 Core 2 Duo Mac mini Server with 8 GB of RAM, it took approximately 5 hours).

Once installed (gimp2-devel will be the very last package to be compiled and installed), you can run it, again from the Terminal:

$ gimp

It is an X11 program, so this command will first launch X11 or XQuartz (in your Utilities folder), and then the GIMP.

One problem is that there are only two default themes, so, if you want a better look and feel, just take the additional themes from the current OS X version of GIMP, available from here (the Snow Leopard version works fine in Lion).

To get the additional themes ('Glossy P', 'Leopard', 'ProApp' - rather cool! - and 'Tiger') also in GIMP 2.7.3, just copy them from

/Applications/Gimp.app/Contents/Resources/share/gimp/2.0/themes

into

/opt/local/share/gimp/2.0/themes.

Obviously, also this one is not an optimal solution, as it takes several hours to compile everything from source, but it can always be interesting as an experiment.

The best thing would of course be if eventually there were a precompiled version available, from the 'Gimp on OS X' site or elsewhere: so, let's hope that this will be the case, at least for the final GIMP 2.8 release.

[crarko adds: On the off chance that someone reading this doesn't already know, The GIMP is an image manipulation program, along the lines of Photoshop. One of the big winners of open source.

P.S. The site was hit with a ton of spam, and while I'm cleaning that up this will be the only hint published today. Hopefully things will be better tomorrow.]
  Post a comment  •  Comments (9)  
  • Currently 3.67 / 5
  You rated: 5 / 5 (6 votes cast)
 
[8,270 views]  View Printable Version
10.7: Removing a Delay in SSH commands to some hosts UNIX
Using SSH to connect to some servers can introduce long delays from the time the command is issued until the connection with the server is established. This hint describes two potential problems and offers a solution.

In connecting to a local server, my ssh command would take about 20 seconds to complete. Non-Macintosh clients would not see this delay. After searching for the web and slogging through a number of posts that suggested how to change the server to fix ssh delays, I pieced together enough information to find out how to change my client configuration to solve the problem.

The first, and largest cause of delays, was my client and the server working to authenticate me using 'GSSAPI' (Kerberos) authentication. That seemed to be a good 15-18 seconds of the delay. I fixed this problem by adding a configuration file for my user that disabled GSSAPI authentication for the host. The file I added is ~/.ssh/config and I created it to read:
Host -host-name-here-
 GSSAPIAuthentication no
 GSSAPIKeyExchange no
Where -host-name-here- is replaced with the name of the host so that it matches whatever you type into the ssh command. If you want to disable GSSAPIAuthentication for all hosts you can use an asterisk '*' as a wildcard host name.

That took the delay down to about a second or two. Based on another hint found in this forum, I discovered that the Mac also tries to negotiate with the server through both IPv4 and IPv6 channels. This server doesn't do IPv6 so I changed my ssh config to read:
Host -host-name-here-
 GSSAPIAuthentication no
 GSSAPIKeyExchange no
 AddressFamily inet
This forces ssh to use only IPv4 and made my ssh connections almost instantaneous.

[crarko adds: I haven't tested this one.]
  Post a comment  •  Comments (11)  
  • Currently 4.33 / 5
  You rated: 1 / 5 (6 votes cast)
 
[9,332 views]  View Printable Version
Automatically update locate db on-demand UNIX
This hint provides a method to automatically insure that the locate db is not too old (but only) whenever you use the locate command (in Terminal or a script).

The hint:
  • a) uses sudo to update the db as root,
  • b) assumes you're using bash as your shell interpreter,
  • c) sets an alias so as to be transparent,
  • d) adds "-i" to your locate command, making it case-insensitive,
  • e) considers the db outdated if it's older than an hour, (actually 3600 seconds, which you can change of course.)
Using your favorite text editor add the following line to the file called ~/.bash_profile. It's inside your Home directory as indicated but hidden. If it doesn't already exist you can create a new text file and save it to that path and name.
alias locate='if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo "locate: db is too old!">/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i'

[crarko adds: Note that in creating the command alias you slightly change the meaning of the locate command; you can use a different alias if you want to keep both ways around and update manually. You lose some of the value of the hint if you do that.]
  Post a comment  •  Comments (5)  
  • Currently 2.40 / 5
  You rated: 1 / 5 (5 votes cast)
 
[11,748 views]  View Printable Version
10.7: View Linux SMB servers in Path Finder UNIX
I use Path Finder for some fancier features, but since upgrading to Lion, I could not see my Linux SMB server in the side panel. After waiting for their Lion patch with no change, I figured out a very simple solution.

For whatever reason, Path Finder can't find or list Samba servers like it did in Snow Leopard. But, if you either install or modify an Avahi daemon on the SMB server, and advertize SMB services, Path Finder will see the server again.

After installing the Avahi daemon in a manner appropriate for your distribution, just create and save this simple file to /etc/avahi/services (on the server):
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

   Samba Shares on %h
   
       _smb._tcp
       139
This worked as is for me, and the server popped up in Path Finder within seconds, and remains in the side panel even after all the shared mounts were removed.

Hope this helps someone else who is sick of opening a Finder window just to connect to another share, or is sick of hitting Command-K every few minutes.

[crarko adds: I haven't tested this one. I'd guess this is because Lion no longer uses Samba for SMB support. Note: there was originally a link in the hint to a Gentoo Linux wiki as a source for this fix, but that site seems to have crashed. Avahi is a multicast DNS zeroconf (Bonjour-compatible) service discovery system. As the hint suggests, you should be able to find it for most Linux distributions.]
  Post a comment  •  Comments (3)  
  • Currently 3.80 / 5
  You rated: 3 / 5 (5 votes cast)
 
[5,975 views]  View Printable Version
Automatically cd to active Finder directory in new Terminal window UNIX
There exist small apps that will open a new Terminal window or tab and automatically cd to the directory of the active Finder window. This hint describes a way to have the Terminal always cd to the directory of the active Finder window whenever you open a new Terminal window or tab -- without the use of an app or any other third-party solution.

In other words, whenever you open a Terminal window or tab, if there is an open Finder window, the Terminal will start in the directory shown in the Finder window.

To make this happen, all you need to do is add the following line somewhere in your .bash_profile file in your home directory:
cd `osascript -e 'tell application "Finder" to if window 1 exists then if target of window 1 as string is not ":" then get POSIX path of (target of window 1 as alias)'`
To edit your .bash_profile file, open Terminal and enter the command:

open ~/.bash_profile -a TextEdit

Paste the code on an empty line anywhere in the file, and save the file. If Terminal complains that .bash_profile doesn't exist, create it with this command:

touch ~/.bash_profile

Then edit it as described.

If you want a quick way to cd to the active Finder directory manually, add the following code to your .bash_profile:
alias cdf='cd `osascript -e "tell application \"Finder\" to if window 1 exists then if target of window 1 as string is not \":\" then get POSIX path of (target of window 1 as alias)"`'
Upon opening a new Terminal window, you'll be able to cd to the active Finder directory by just entering cdf at the prompt. If you'd rather use a different shortcut, substitute your own string in the above code, after 'alias ' and before the equals sign.

(The alias hint is similar to this hint, but discovered independently.)

Note: If you use the 'cdf' alias when there is no open Finder window, or when the active Finder window is showing something other than a directory, you will be taken to your home directory.

[crarko adds: I tested this, and it works as described.]
  Post a comment  •  Comments (14)  
  • Currently 4.00 / 5
  You rated: 2 / 5 (8 votes cast)
 
[6,621 views]  View Printable Version
10.7: Disable alternate screen use in xterm terminals UNIX
In Lion the xterm terminal settings have been updated and now emacs, vi, less, pine, and more, among others use the 'alternate screen' feature in which the screen is cleared after the process quits. Here is a way to restore the previous behaviour, in which the final screen remains in the scrollback.

I found this in a post by Chris Johnsen, who explains how it works.

For example let us suppose that you are using the default terminal: xterm-256color. (See Terminal.app>>Preferences>>Settings>>Advanced.) At the command line type:

infocmp | sed -e 's/[sr]mcup=[^,]*,//' > /tmp/noaltscreen-terminfo

Press Return and then type:

tic -o ~/.terminfo/ /tmp/noaltscreen-terminfo

This creates a file ~/.terminfo/78/xterm-256color in your home directory. When you open a new Terminal.app window the local file is used, while other users get the default Lion behavior.

[crarko adds: I haven't tested this one. In the referenced post above it is also suggested that the command man something | more will accomplish the same effect just for man pages without changing the overall behavior of the terminal.]
  Post a comment  •  Comments (5)  
  • Currently 3.50 / 5
  You rated: 1 / 5 (6 votes cast)
 
[4,667 views]  View Printable Version
Running winexe on the Mac UNIX
If you are a Unix admin and also have to maintain Windows servers, you will find winexe a must command line utility to have in your arsenal.

Until recently I have been able to do this only on Linux boxes. I have compiled it and it works great however, on Mac OS X I have not had any luck until a few days I came across this site. There are also links provided to the winexe binary packages here.

So, once you install it, the usage is simple:

Here is a quick exemple.

To get the route table on the Windows machine (using your correct IP address and other appropriate information):

winexe -U YOURDOMAIN/YourAccount%YourPassword //172.16.2.xxx 'route print'

If you want to start a Windows service:

winexe -U YOURDOMAIN/YourAccount%YourPassword //172.16.2.xxx 'net start "Service Name"'

Or to kill a Windows service:

winexe -U YOURDOMAIN/YourAccount%YourPassword //172.16.2.xxx 'Process.exe -k 1110'

[crarko adds: I haven't tried this, but the first link will get you to the source code (GPL) so you can examine and build it for yourself. The second link points to a number of useful tools you can run in Terminal to work with Windows machines. I did a quick check of MacPorts and Fink and they didn't seem to have winexe, at least not as a standalone package.]
  Post a comment  •  Comments (3)  
  • Currently 4.00 / 5
  You rated: 5 / 5 (4 votes cast)
 
[6,481 views]  View Printable Version
10.7: Use Terminal proxy icons in zsh UNIX
The useful site macosxautomation.com reveals that Terminal.app in Lion can use proxy icons, those document icons to the left of the window title in many apps. Right-clicking on that icon opens a menu and you can open your current directory (or its parents) in the Finder. You can also drag the proxy icon onto the desktop to create an alias to your current directory.

If you don't use bash (the default shell on Mac OS X), you won't see the new proxy icons, though.

Here's how I extended the proxy icons feature to zsh. To work, your shell has to use special escape codes to pass the current directory to Terminal.app. This is the same mechanism used to set custom title bars.

Apple placed code in /etc/bashrc to support proxy icons. With slight modification, that code can go into your ~/.zshrc and do the same thing:
update_terminal_cwd() {
    # Identify the directory using a "file:" scheme URL,
    # including the host name to disambiguate local vs.
    # remote connections. Percent-escape spaces.
    local SEARCH=' '
    local REPLACE='%20'
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
    printf '\e]7;%s\a' "$PWD_URL"
}
autoload add-zsh-hook
add-zsh-hook chpwd update_terminal_cwd
update_terminal_cwd
The update_terminal_cwd function is Apple's, taken from /etc/bashrc. The last three lines are mine. They set up the proxy icon at the beginning of the shell session, and cause it to be updated every time you change directory. The code to do that in bash won't work in zsh.

[crarko adds: I haven't tested this one.]
  Post a comment  •  Comments (4)  
  • Currently 3.25 / 5
  You rated: 2 / 5 (4 votes cast)
 
[4,941 views]  View Printable Version