Create a Mac OS X application from a Java jar

Leave a comment

Apple’s developer tools come with a neat utility for bundling Java jar file into a Mac OS X application: Jar Bundler.

It can be found at /usr/share/java/Tools on Lion.

First add your Jar file to the “Additional Files and Resources” panel. It should contain a Main Class (i.e. be a Java Application).

Specify the Java Main Class name and other Mac OS X specific options (e.g. Application icon, whether Java Swing’s JMenuBar should use the Mac OS X menu bar…).

Finally, specify other Application specific properties (e.g. version). You can also specify the JVM heap memory size (in MB) and other JVM options from here.

There you go, here is the Package Contents of the resulting Mac OS X application!

The resulting application is now well integrated into Mac OS X as shown in this Finder Get Info dialog.

The Java app used in the above example is PageSucker. The latest version is 3.2 but only exists for Windows, Mac OS 9 (Classic) and Mac OS X, but for PowerPC only. Using the instructions in this post will allow you to create an Intel compatible application for Mac OS X (including Lion…).

If you are lazy, you can get the version I did for Mac OS X 10.7 Lion: PageSucker.app.zip (not a real PDF, but a zip file…).

Set the visibility of files and folders on Mac OS X

Leave a comment

This is a bit of legacy from Apple’s Pre-Mac OS X systems: files or folders could be set invisible (via software like FileBuddy) or locked (via the Finder)…

In Mac OS X, if you have installed Apple’s free developer tools, these contain a command line utility to manipulate HFS+ attributes:

which setfile ; setfile -h
/usr/bin/setfile
Usage: SetFile [option...] file...
-a attributes # attributes (lowercase = 0, uppercase = 1)*
-c creator # file creator
-d date # creation date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
-m date # modification date (mm/dd/[yy]yy [hh:mm[:ss] [AM | PM]])*
-P # perform action on symlink instead of following it
-t type # file type


Note: The following attributes may be used with the -a option:
A Alias file
B Bundle
C Custom icon*
D Desktop*
E Hidden extension*
I Inited*
M Shared (can run multiple times)
N No INIT resources
L Locked
S System (name locked)
T Stationery
V Invisible*
Z Busy*


Note: Items marked with an asterisk (*) are allowed with folders
Note: Period (.) represents the current date and time.
Note: [yy]yy < 100 assumes 21st century, e.g. 20yy

See also man SetFile

File sharing with Mac OS X 10.7 Lion

Leave a comment

Before Mac OS X Lion, in System Preferences > Sharing > File Sharing > Options… you had the option to use FTP to share your files. Note that this did not enable the FTP anonymous user, which needed some Terminal wizardry. Instead, you could use PureFTPd Manager to have a nice GUI to configure FTP with anonymous user access, but Lion is not supported (yet?).

Since Mac OS X Lion, Apple removed the GUI to enable FTP file sharing. FTP protocol has probably been deemed too unsecure (your password string and any data would travel the ether without any encryption).

Only AFP or SMB (CIFS) remain in Lion’s File Sharing Preference Pane. The FTP checkbox is gone…

What if I simply want a quick and easy way to share files with others without the need for an account or password?

This is the whole point of setting up a FTP server with an anonymous user!

So what’s the alternative for Lion’s users?

You can still enable FTP in Lion, but now only via the Terminal with administrative permissions:

  1. Add the FTP service to the launchd database (the FTP daemon will be started at the same time and restarted on demand):
    sudo launchctl load -w /System/Library/LaunchDaemons/ftp.plist
  2. Stop (temporarily) the FTP daemon: 
    sudo launchctl stop com.apple.ftpd
  3. Start (after a stop) the FTP daemon: 
    sudo launchctl start com.apple.ftpd
  4. Remove the FTP service from the launchd database:
    sudo launchctl unload /System/Library/LaunchDaemons/ftp.plist

Easy for the Terminal addicts, but like before via the GUI, FTP in Mac OS X still lacks an anonymous user (see man ftpd for more info).

Luckily, for the rest of Mac users, there is a more secure protocol and it can be easily configured using only the System Preferences GUI.

Simply create a standard user in the Users & Groups System Preference Pane. You can decide to set it with a password that you will share with others (e.g. the same as its userid).

In the absence of a pre-configured anonymous FTP user in Mac OS X, the next best thing is to create a dummy user with permissions restricted to only upload / download files…

You can further limit what this user could do (particularly locally) by enabling Parental Controls (i.e. degrade it from standard to managed user).

If you go for a no password dummy user account, remember to enable Parental Controls to restrict what this user can do (e.g. disable changing the password, Time Limits…)

Finally, enable Remote Login in the Sharing Preference Pane. This will enable ssh remote login, but implicitly and more importantly for us: sftp.

Enabling Remote Login will also enable the SecureFTP service. Also consider limiting access only to the dummy user if you created one…

Others can now access the files held by user with the address sftp://user@<ip or hostname> or by using the equivalent command in a Terminal: sftp user@<ip or hostname>.

If you do not want to have to share an IP address, consider using a free dynamic DNS service

Mac OS X Lion – opendirectoryd bug?

2 Comments

Symptoms since using Mac OS X Lion (still relevant in the latest version of Lion: 10.7.5 released on 19 September 2012):

  • Your Mac starts feeling sluggish with some unexplained CPU usage
  • Your are unable to start any Application (even logout or restart as this needs to spawn a new process under the hood… your only chance is to switch user)
  • You are unable to open the Terminal or use certain commands in it:
    • id
    • sudo
    • whoami
  • You are no longer you (reported as User ‘????’ in Activity Monitor)
  • Your console is filled with message similar to this:
    • xpchelper[123]: getpwuid_r() failed for UID: 501, ret: 0, errno: 0

If you search the web for the above, you will see that you are not alone having this problem…

Activity Monitor showing higher than usual CPU usage. Note that the sum of highest % CPU Processes is less than the reported % User and % System combined.

Oh my God!!! Terminal won’t even start!

No wonder your Mac is slow… Look at the rate of logging in the Console application! One pid gets created every 20 ms on my MacBook…

So, what is the way to deal with this until Apple issues a fix in a future update (this bug seems to have been fixed since Mac OS X Mountain Lion 10.8)?

Well, if you had Activity Monitor or a Terminal running before the problem occurred, you can simply quit the process named opendirectoryd (it will be automatically restarted by launchd) and then magically, your Mac will behave normally again.

Alternatively, switch user to kill opendirectoryd from the new session with administrative rights.

Quit / Force Quit opendirectoryd from the list to get back to normal…

There you go, %CPU back to normal, opendirectoryd automatically restarted, your Mac is now back to normal.