Mac
From Shiftyjelly
Contents |
Apple Links
Apple Australia
Apple Store
Apple US
Downloads
Apple Discussions
Developer Connection
Concise Mac Intro
OSX Hints
Cool Mac Freeware
Snow Leopard Compatibility
Dev Programs That Work Fine
Netbeans, Eclipse, Xcode, Simply DB, Ardzip, Viscosity (32 bit kernel mode only)
Installing Java 1.5
http://daveyshafik.com/archives/721-fixing-zde-5-5-in-snow-leopard.html
Fixing MySQL
The MySQL that was installed for Leopard does not function under Snow Leopard. Here is how to update it:
grab the latest version of macports (if you already have macports, then just run selfupdate):
svn co http://svn.macports.org/repository/macports/trunk/base/ macports
build it
cd macports ./configure make sudo make install sudo /opt/local/bin/port -v selfupdate
Install Mysql5:
sudo port install mysql5 sudo port install mysql5-server --if this is a fresh install and you need to configure the DB sudo -u mysql mysql_install_db5
Copy your old MySQL data:
sudo bash cd /opt/local/var/db/mysql5 rm -rf * cp -r /usr/local/mysql-5.0.67-osx10.5-x86/data/* . chown -R _mysql *
Start Mysql5:
cd /opt/local ; sudo /opt/local/lib/mysql5/bin/mysqld_safe &
Set MySQL to launch at system startup:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Fix MySQL Query Browser and Admin Tool, these both work fine, but need to be told where the new .sock file is (expand the advanced arrow):
/opt/local/var/run/mysql5/mysqld.sock
Fixing Stunnel
The latest openssl and stunnel from macports seems to be a bit broken on snow leopard. You can grab the older version by copying over these files:
openssl, stunnel in /opt/local/bin libssl.* in /opt/local/lib/ libcrypto.* in /opt/local/lib/
once you've done that if you do an stunnel -version it should have reverted to a previous version
Bugs and Fixes
Get Spotlight to index Thunderbird mail
Get Spotlight to not index the virtual machines applications and files
System Preferences -> Spotlight -> Privacy -> "Add the virtual machine folders"
Show/Hide Hidden Items In Finder
To show and hide hidden items in Finder, run the following commands in Terminal: To show hidden items:
- defaults write com.apple.Finder AppleShowAllFiles TRUE
- killall Finder
To hide them again:
- defaults write com.apple.Finder AppleShowAllFiles FALSE
- killall Finder
Automatically get rid of the Print Queue when printing is finished
Symptom: You issue a print job and the print queue for the printer keeps hanging around on your dock
Solution: Right click the print queue and enable "Auto Quit"
Pointers for People Switching From Windows
- All the shortcuts are different, deal with it.
- Unlike the windows trash can, the mac one has no idea where your files came from, and they can not be automatically restored.
- In Windows copying over a folder with another folder of the same names just adds to the existing folder. On the mac it completely replaces it, so be careful when overwriting things.
Terminal Tips
- There's a file called '.profile' in your home folder that controls all of your variables etc (like PATH). A typically JAVA configuration might look like this:
alias ll="ls -la" export MAVEN_HOME=/Applications/maven-1.0.2 export M2_HOME=/Applications/maven-2.0.4 export M2_REPO=~/.m2/repository export ANT_HOME=/Applications/apache-ant-1.7.0 export PATH=/Applications/TextEdit.app/Contents/MacOS/:$MAVEN_HOME/bin:$M2_HOME/bin:$JAVA_HOME/bin:$ANT_HOME/bin:/usr/local/bin:/usr/local/mysql/bin:$P ATH export GWT_HOME=/Applications/gwt-mac-1.4 export GWT_EXTERNAL_BROWSER=firefox export CATALINA_HOME=/Applications/apache-tomcat-5.5.23 export AXIS_CLASSPATH=/Applications/axis-1_4/lib/axis.jar:/Applications/axis-1_4/lib/commons-discovery-0.2.jar:/Applications/axis-1_4/lib/commons-loggi ng-1.0.4.jar:/Applications/axis-1_4/lib/jaxrpc.jar:/Applications/axis-1_4/lib/saaj.jar:/Applications/axis-1_4/lib/log4j-1.2.8.jar test -r /sw/bin/init.sh && . /sw/bin/init.sh
- grep for particular files
Just java files in current directory and subdirectories: grep -r --include="*\.java" "Test" .
- Port forward from one local port to another (handy if you want to pretend something like MySQL is running on 3305 and 3306)
sudo ipfw add fwd localhost,3306 tcp from any to any 3305 via lo0
- Open a directory in finder
open .
- Open a directory in textmate
mate .
- Open a file in the application that normally opens it
open test.pdf
- Set title to user@hostname: directory. Add the following to your .profile or .bashrc file
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
How to slow your internet speed for testing
slowNet.sh
#!/bin/sh /sbin/ipfw add 100 pipe 1 ip from any 3000 to any out /sbin/ipfw add 200 pipe 2 ip from any 3000 to any in /sbin/ipfw pipe 1 config bw 128Kbit/s queue 64Kbytes delay 250ms /sbin/ipfw pipe 2 config bw 128Kbit/s queue 64Kbytes delay 250ms
normalNet.sh
#!/bin/sh /sbin/ipfw delete 100 /sbin/ipfw delete 200
Keyboard Shortcuts
- CMD + Left : Move the cursor to the start of the line
- CMD + Right : Move the cursor to the end of the line
- CMD + Space : Open spotlight search box
- CMD + Esc : Open Front Row
- CMD + Shift + 3 : Screen shot (saved to the desktop)
- CMD + Shift + 4 : Abstract user defined area screen shot
- CMD + Q : Quit application
- CMD + W : Close current window
- CMD + , : Application preferences
- F9 : Show all windows
- F10 : Show all windows in one application
- F11 : Show desktop
- F12 or middle mouse button : Show dashboard
Applications
TextMate - Text editor/IDE (esp. useful, but not limited to, Ruby on Rails)
Apple Script - "AppleScript is an English-like language used to write script files that automate the actions of the computer and the applications that run on it."
Butler - Butler's purpose is to make it easier for you to perform different â potentially recurring â tasks.
Chax - iChat plugin for tabs and other features.
Namely - Mini application launcher. To start hit Option + Esc
Quicksilver - More in depth application launcher and command linker. To start hit Control + Space
Adium - Chat client that links to MSN, AIM, Google ...
Tips
- To resize a sparse image, make sure it's unmounted then run:
hdiutil resize -size 10g
10g = 10 Gigabytes, but you can specify whatever size you want
- To include the Date in your time on the top menu bar. Follow these instructions.
- My CD/DVD won't eject. Restart your Mac, and when it starts up again, hold down the mouse key.
- Add colour to your ls in terminal by adding this line in your .bashrc file.
alias l='ls -lG' alias ll='ls -alG'
- Add colour to your vi (everybody loves vi) with this .vimrc file. The .vimrc file should exist in your home directory. If it doesn't, create one.
- To set the default application that opens for a particular kind of file (eg: open .doc in NeoOffice), right click on a file with the extension and choose 'Get Info'. Under the Open with section choose the program you want to open all files of this type with, then press the Change All button to update this setting.
- Find out where all your disk usage is being used with
du -h -depth1 *
- How to copy a CD or DVD
File Sharing
- Click on System Preferences
- Click on Sharing
- Click on File Sharing
- Press the + button under the Shared Folders list and select the folder you want to share
- Select Users and Permissions
- Close System Preferences screen. This will share folder BUT only for that folder NOT subfolders.
- Open Finder and find folder you shared above
- Right Click folder and Press "Get Info"
- Open Sharing & Permissions
- Click Padlock and enter your system password
- Make sure privileges are correct
- Click on Gear button at bottom and select "Apply to enclosed items"
Screen Sharing
- The Screen Sharing application is found under /System/ Library/CoreServices. Do not start yet.
- Open up Terminal and run the following command
defaults write com.apple.ScreenSharing 'NSToolbar Configuration ControlToolbar' -dict-add 'TB Item Identifiers' '(Scale,Control,Share,Curtain,Capture,FullScreen,GetClipboard,SendClipboard,Quality)'
- Now when you open up Screen Sharing you will have a few extra buttons on your toolbar.
Developing For The Mac
General
- Build a disk image (just like most commercial apps have): instructions
Java
- To add your application's menu in the Macintosh Menu Bar, add the following in the VM Options in the Jar Bundler tool.
-Dapple.laf.useScreenMenuBar=true
- To set the types of files that your application can handle, edit the Info.plist file (right click on your application, choose show package contents, then go down one directory to where the file is). For example, to set your application to allow any file to be dropped onto it:
<key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>*</string> </array> <key>CFBundleTypeName</key> <string>Generic Document</string> <key>CFBundleTypeOSTypes</key> <array> <string>****</string> </array> <key>CFBundleTypeRole</key> <string>Viewer</string> </dict> </array>
- The easiest way to handle mac specific events in your code, is to use the macify library: [1]
- To detect whether you're in OS X in JAVA:
public static boolean isOSX(){
return System.getProperty("os.name").toUpperCase().indexOf("OS X") >=0;
}
- If your code needs to run in Java 1.6, you can package it use 'Jar Bundler' for the mac. You may need to add this parameter to your info.plist file to make it work with the preview build of Java 1.6 for the mac:
<key>JVMArchs</key> <string>x86_64</string>
- Making your Java app shine on OS X [2]
- Apple Java Extensions API [3]
- Using Locales on your Mac. When you want to get the default Locale on your Mac, eg:
System.out.println("Locale="+Locale.getDefault());
You must ensure you select your Language correctly:
- Open System Preferences > International > Language.
- Click 'Edit List' > Check 'Australian English' > OK
- Ensure that 'Australian English' appears at the top of your list of Languages.
Automation
Ruby OSA
RubyOSA is a ruby library that lets you access AppleScript functionality on your mac. This comes in handy when you want to automate systems tasks or interact with applications in a friendly object orientated way, instead of in the weird pseudo code language that is AppleScript.
It's as simple as:
sudo gem install rubyosa
And then you can do things like:
require 'rbosa'
itunes = OSA.app('iTunes')
track = itunes.current_track
p track # <OSA::Itunes::FileTrack:0x1495e20>
p track.name # "Over The Rainbow"
p track.artist # "Keith Jarrett"
p track.duration # 362.368988037109
p track.date_added.to_s # "2006-06-30"
p track.enabled? # true
# Play the selected track.
itunes.play
# Fade the volume.
100.times { |i| itunes.sound_volume = i; sleep 0.1 }
# Set iChat's status message to the current track.
OSA.app('iChat').status_message = "Playing: #{track.name}"
To find out what functions a given application has available:
rdoc-osa --name "iTunes" --op DirectoryToStoreDocIn or for system level things: rdoc-osa --name "System Events" --op DirectoryToStoreDocIn