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

Start MAMP at login without password request UNIX
Running MAMP on standard ports (80 for Apache and 3306 for mySQL) makes MAMP ask for a password on each start up. I would like MAMP to start automatically when I log in, without requiring a password. There are a few ways to do this posted around the web, but they all involve hacking MAMP in one way or another. There is an alternative. Create the following AppleScript in AppleScript Editor:
do shell script "/Applications/MAMP/bin/startApache.sh &" password "YOURPASSWORD" user name "YOURUSERNAME" with administrator privileges
do shell script "/Applications/MAMP/bin/startmySQL.sh > /dev/null 2>&1"
Replace YOURPASSWORD and YOURUSERNAME with the proper values, then save it as a run-only application -- to keep anyone from being able to open the script and read your password. Then add that script to your login items. That's it, you're done!

[robg adds: This hint originally appeared in this blog entry; it was submitted here by the blog's owner. I've reproduced it as it was, with one clarifying note and some minor formatting changes to fit our site layout.]
  Post a comment  •  Comments (10)  
  • Currently 2.93 / 5
  You rated: 4 / 5 (15 votes cast)
 
[23,455 views] Email Article To a Friend View Printable Version
Make X11 Gimp Tool Kit (GTK) apps look much more Mac-like UNIX
It's a well know fact that running X11 applications on ae Mac crates a lot of ugliness. I discovered a way to solve this, at least partially.

A lot of Unix applications use the Gimp Tool Kit, or GTK for short. You can install GTK on Mac via MacPorts by running sudo port install gtk2 in Terminal. There are some themes in MacPorts as well to make your app look like an Air app instead of Win95; they work, but the look is still alien.

However, there is a GTK theme called mac4lin that emulates the Mac look on Linux, but I discovered this can be used on the Mac as well. Download and extract mac4lin and extract and copy one of the archives in the GTK folder to /opt/local/share/themes. Then run gtk-chtheme from MacPorts to change to your new aqua theme. As a final step, click the Font button to set the font to Lucida Grande 10pt, and you're done.

Detailed instructions and screenshots can be found on my blog.
  Post a comment  •  Comments (4)  
  • Currently 2.50 / 5
  You rated: 1 / 5 (14 votes cast)
 
[10,474 views] Email Article To a Friend View Printable Version
See and post Twitter messages from Terminal UNIX
I found a couple of ways to update Twitter and read recent updates from the OS X command line. For instance, you can get all your tweets using the command line by using this command. (For some reason, retweets only show up as an "@" symbol, but your actual tweets will display correctly.)
curl -s http://twitter.com/your_user | grep '<span class="entry-content">' | cut  -d">" -f2 | cut -d"<" -f1
You can update twitter by using this command:
curl -u your_user:your_password -d status='This is My update' https://twitter.com/statuses/update.xml
[robg adds: I haven't tested these.]
  Post a comment  •  Comments (23)  
  • Currently 2.63 / 5
  You rated: 1 / 5 (19 votes cast)
 
[12,126 views] Email Article To a Friend View Printable Version
10.6: Create a new Service to 'tar' directories or files UNIX
Snow Leopard only hintWhen I need a container of files, or of a directory that is already compressed (i.e. jpg images), there is no need to 'compress' into a zip file, so the following OS X Service will replicate the Compress 'right-click' with tar:
  1. Open Automator and select Service from the main screen.
  2. Set the 'Service Receives Selected' pop-up menu to Files or Folders, and set the 'in' pop-up to Finder.
  3. Drag Utilities » Run Shell Script into the workflow area.
  4. Set the 'Pass input' pop-up to as arguments.
  5. Delete all of the sample code, and replace with this:
    Tarfile="$1.tar"
    count=1
    cd "${@%/*}"
    if [ $# -eq 1 ]; then 
      while [ -e "$Tarfile" ]
      do
        let count++
        Tarfile="$1 $count.tar"
      done
    else 
      Tarfile="Archive.tar"
      while [ -e "$Tarfile" ]
      do
        let count++
        Tarfile="Archive $count.tar"
      done
    fi
    /usr/bin/tar -chf "$Tarfile" "${@##*/}"
  6. Select File » Save and name your new Service (Package into Tar or whatever).
  7. Quit Automator and try your Service in the Finder with a selection of files.
[robg adds: This worked as described for me.]
  Post a comment  •  Comments (5)  
  • Currently 2.94 / 5
  You rated: 4 / 5 (18 votes cast)
 
[5,928 views] Email Article To a Friend View Printable Version
Use a shell script and Growl to report a router's status UNIX
Growl my Router Alive! is a bash shell script that will ping an IP address (ie a router) and will notify you, using Growl, if the ping is successful. This requires some Terminal basics, both Growl and growlnotify being installed, and a document with a notification icon for Growl. Enjoy.

I wrote this because I have a wireless connection with a D-Link router that is quite annoying because it sometimes drops its wireless network or internet connection. This script will keep pinging my router and sends an alert when the wireless connection is dropped, and when it comes online again.

Here's the code:
#!/bin/sh

#Growl my Router alive!
#2010 by zionthelion73 [at] gmail . com
#use it for free
#redistribute or modify but keep these comments
#not for commercial purposes

iconpath="/path/to/router/icon/file/internet.png"
# path must be absolute or in "./path" form but relative to growlnotify position
# document icon is used, not document content

# Put the IP address of your router here
localip=192.168.1.1

clear
echo 'Router avaiability notification with Growl'

#variable
avaiable=false

com="################"
#comment prefix for logging porpouse

while true;
do
if $avaiable
then
  echo "$com 1) $localip avaiable $com"
  echo "1"
  while ping -c 1 -t 2 $localip
    do
      sleep 5
    done
  growlnotify  -s -I $iconpath -m "$localip is offline"
  avaiable=false
else
  echo "$com 2) $localip not avaiable $com"
  #try to ping the router untill it come back and notify it
  while !(ping -c 1 -t 2 $localip)
  do
   echo "$com trying.... $com"
   sleep 5
  done
  
  echo "$com found $localip $com"
  growlnotify -s -I $iconpath -m "$localip is online"
  avaiable=true
fi

sleep 5

done
Copy this script into a directory as a script named pingrouter.sh or whatever; the name of your shell script must end with a .sh. Make the script executable by typing chmod ugo+x pingrouter.sh. Execute the script with sh ping.sh. Comments and suggestions are always welcomed!

[robg adds: I haven't tested this one.]
  Post a comment  •  Comments (6)  
  • Currently 2.57 / 5
  You rated: 1 / 5 (14 votes cast)
 
[9,548 views] Email Article To a Friend View Printable Version
Fix a bug in snmp output to show data for new Mac mini UNIX
I've searched for a command line tool to integrate in my mrtg page. It should fetch the temperature and fans peed from the system on my Mac mini. Apparently snmpd can do this.

After starting snmpd, I stumbled across /usr/share/snmp/SensorDat.xml. There is an entry there for my Mac mini, but it didn't workL:
    <key>MacMini3,1</key>
    <dict>
        <key>fan_data</key>
I downloaded the net-snmp-source from Apple, and found a test program in this directory:
net_snmp/Build/net-snmp/agent/mibgroup/ucd-snmp/data_access/
read more (329 words)   Post a comment  •  Comments (3)  
  • Currently 2.67 / 5
  You rated: 1 / 5 (12 votes cast)
 
[6,648 views] Email Article To a Friend View Printable Version
Execute small bits from the clipboard in Terminal UNIX
Perl and Bash programmers will recognize the backtick operator (`some_command`) as a way to cause the string enclosed in the backticks operator (some_command) to be executed as a command in the shell.

If you put some executable text on the OS X clipboard, this can also be directly executed with the backtick operator. For example, the shell command ls -l -G -a -F $HOME produces a colorized long listing of the user's home directory. Copy that command to the OS X clipboard.

In Terminal, type pbpaste, and you will get the text of the command. If you instead type `pbpaste`, the shell will execute the command and produce the directory listing.

[robg adds: This tidbit is most useful as part of a larger script, as seen in these examples. If you're in Terminal with some executable Unix command on the clipboard, you could run that command directly by pressing Command-V and Return.]
  Post a comment  •  Comments (10)  
  • Currently 2.42 / 5
  You rated: 5 / 5 (19 votes cast)
 
[8,848 views] Email Article To a Friend View Printable Version
Use Spotlight to speed up grep searches UNIX
The grep -ri command (recursively search for matches, ignoring case) in Terminal is incredibly useful, but incredibly slow. In OS X, we can leverage mdfind to quickly find the files containing our search string, then use grep to find the strings within only those files. Here's a script to do just that.
#!/bin/bash
#
# Spotlight metadata find and grep by Daniel.Hoherd at gmail dot com

## Check for at least two arguments, print usage if else
if [ $# -lt 1 ] ; then
  echo "usage: $0 searchstring [dir or file] [dir2 or file2]"
  exit ;
fi

ss=$1;
shift;
files=$@;

until [ -z "$1" ] ; do
  thisitem=$1
  onlyin="-onlyin '$thisitem' $onlyin"
  shift
done;
eval mdfind -0 $onlyin "$ss" | xargs -0 grep -Hi "$ss"
Leveraging mdfind to eliminate files that do not contain the matching string makes this operation an order of magnitude quicker, cutting it to mere seconds instead of minutes on over 100GB of data in my tests. The downside to this is that Spotlight does not index every directory, so you may be missing some files such as system files.

If you don't want to use this script, the same thing can be accomplished by hand by writing mdfind -0 -onlyin searchdir searchstring | xargs -0 grep -Hi searchstring. I've included the -H and -i options to more closely match the output of mdfind, but you can safely remove them.
  Post a comment  •  Comments (7)  
  • Currently 3.32 / 5
  You rated: 4 / 5 (22 votes cast)
 
[10,375 views] Email Article To a Friend View Printable Version
Use a third-party APC UPS management tool for more control UNIX
My APC UPS beeps whenever the power fails. If this happens at night, the beep is loud enough to wake people. The beep can be disabled by software in Windows, but not in the Mac version of PowerChute Personal Edition. The Mac version provides features that Mac OS X already provides: shutdown timers for any UPS connected via USB.

I stumbled across the open source Unix app Apcupsd which gives me all the features I want from the Windows version of PowerChute: beep settings, battery change dates, and so forth. Furthermore, it can send email notifications for significant events. As someone who runs an old G4 as a home server, this is very nice to know.

After downloading and installing Apcupsd is installed, run this command from Terminal: sudo /sbin/apctest. This will display a simple text-based menu, and it's self-explanatory. If you get an error message that reads Cannot find UPS device..., it could be because:
  1. Only one tool can query the UPS, and the background monitoring process is running, so stop it with sudo /Library/StartupItems/apcupsd/apcupsd stop, then try again.
  2. The software might only work with PowerPC Macs at this point. It works perfectly on my G4, but not on my ICBM (Intel Chip Based Mac).
[robg adds: I haven't tested this app.]
  Post a comment  •  Comments (20)  
  • Currently 4.25 / 5
  You rated: 4 / 5 (24 votes cast)
 
[30,147 views] Email Article To a Friend View Printable Version
Check the status of the online Apple Store via shell script UNIX
Sometimes, like today, I'm particularly interested in the Apple Store's status...as in, when is it back up so that I can order whatever it is I'm waiting to order. While sitting around pressing Command-R this morning, I figured there must be a better way. After a few minutes with curl and GeekTool, I had the solution.

Because I didn't have very much time to implement this trick this morning, I just created a new 'Shell' Geeklet in GeekTool, with the refresh set to every five seconds, that showed the output of this command:

curl -s http://store.apple.com/us | grep backsoon | grep australia

Note that the above is specific both to the US Apple Store, and to the current version of that store. You may have to modify it for other geographies, or for future store site changes. Basically, what the command does is grab the Apple Store page via curl, suppresses the normal output (-s), and then searches for backsoon, which is the name of the GIF image Apple uses for the "We'll be back soon!" graphic.

There are, however, lots of matches for backsoon, so I then grep again for australia, which was the first occurrence of backsoon in the output. This way, I get just one line of output when the store is down. When it's up, there shouldn't be any output.

Testing was real world, too, as I waited for the 5:30am scheduled store opening. About a minute before that, the output from my Geeklet suddenly went blank, so I reloaded the web page, and there was the store. Nifty. For longer-term use, though, my solution leaves much to be desired. So after ordering the iPad, I turned my quick solution into a slightly more robust script that uses Growl to put the alert onscreen. Read on for that version.
read more (290 words)   Post a comment  •  Comments (3)  
  • Currently 3.08 / 5
  You rated: 4 / 5 (13 votes cast)
 
[8,918 views] Email Article To a Friend View Printable Version