[e-lang] Running E-SWT programs on Mac OS X

Kevin Reid kpreid at attglobal.net
Tue May 16 21:53:03 EDT 2006


This script can be used to make a SWT-using E program runnable on Mac  
OS X. It, necessarily, creates an application bundle which you must  
double-click.

This is a minimal working tool. Obvious improvements would be icons,  
reproducible bundle identifiers, etc.

Example: macify-swt.e /Stuff/e/scripts/eChat.e-swt ./eChat.app

#!/usr/bin/env rune
# Copyright 2005-2006 Kevin Reid, under the terms of the MIT X license
# found at http://www.opensource.org/licenses/mit- 
license.html ................

pragma.enable("easy-return")
pragma.disable("explicit-result-guard")

def chmod := makeCommand("chmod")
def setExecutable(file) {
   chmod("+x", file.getPlatformPath())
}

def xmlesc(s :String) {
   return s.replaceAll("&", "&amp;").replaceAll("<",  
"&lt;").replaceAll(">", "&gt;").replaceAll("'", "&apos;").replaceAll 
("\"", "&quot;")
}
def shesc(s :String) {
   return "'" + s.replaceAll("'", "'\''") + "'"
}

def macifySwt(script, target, bundleID, eHome) {
   def contents := target["Contents"]
   def platformDir := contents["MacOS"]
   platformDir.mkdirs(null)

   def shehome := shesc(eHome)

   def executable := platformDir["run"]
   executable.setText(`$\
#!/bin/sh
exec $shehome/rune \
	-J-XstartOnFirstThread \
	-cpb $shehome/src/bin/mac/swt.jar \
	-Djava.library.path=$shehome/src/bin/mac/ppc \
	"``dirname $$0``/script.e-swt"
`)
   setExecutable(executable)

   platformDir["script.e-swt"].setText(script.getText())

   # XXX use an XML (or plist) generator instead
   contents["Info.plist"].setText(`$\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http:// 
www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
         <key>CFBundleInfoDictionaryVersion</key>
         <string>6.0</string>
         <key>CFBundleExecutable</key>
         <string>run</string>
         <key>CFBundleIdentifier</key>
         <string>${xmlesc(bundleID)}</string>
</dict>
</plist>`)
}

def [scriptPath, targetPath] := interp.getArgs()
macifySwt(def script := <file>[scriptPath],
           <file>[targetPath],
           `org.erights.e.mac-bundle.${script.getName()}-$ 
{entropy.nextSwiss()}`, interp.getProps()["e.home"])


-- 
Kevin Reid                            <http://homepage.mac.com/kpreid/>




More information about the e-lang mailing list