It is easy to create ruby OS X app — create structure like this:
xxx.app
└── Contents
├── Info.plist
├── MacOS
│ └── xxx
└── Resources
└── xxx.icns
and put code to execute into xxx. But launch time is noticeable, so I want this app to stay in background and run some method, when app is opened: so when I run that app first time, it executes code an stays in background, when I run another time, app is already in background, so it just runs specified method.
Minimal Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleExecutable</key>
<string>newTabHere</string>
<key>CFBundleIconFile</key>
<string>newTabHere</string>
<key>LSUIElement</key>
<true/><!-- hides icon from Dock -->
</dict>
</plist>
The slowness is due to the start up time required for the ruby interpreter. That is why it is not slow for a bash script or objective-c.
Steps to communicate with background ruby program:
The bash script has to:
Advantages to this solution
Warning
This has the cost of constantly using up the computer’s memory with the ruby interpreter. So, it is not a user friendly solution.
To create a true app with a graphical interface in ruby you have to use macruby with rubycocoa.
Or use the Titanium Desktop from Appcelerator, you will have to write the interface code in javascript but you can do the rest with ruby. This method also has the advantage of being cross-platform. see http://developer.appcelerator.com/doc/desktop/ruby