MacRuby: How to write an app/script that generates native Mac apps? - ruby

So I'm basically trying to recreate what this app: Fluid, already does. I want to write a Ruby script, or MacRuby app that accepts a few parameters and can generate a simple native app.
Since their code is not open-sourced, I can't see how they do it. And I don't know how I would begin to accomplish something like this.
Also, I would like this script to be run on Windows (not that the user could install the generated app, but so the app could be distributed to Mac users).
How could I do something like this?
Solution:
Here is a project that does exactly the same thing that I'm trying to do. It takes an app bundle and does some string replacing on some files in the bundle. I'm going to use it as an example to imitate.
https://github.com/maccman/macgap-rb

MacRuby can already create native app bundles on OS X (it's a compiler as well as an interpreter), so in a sense there's no question to be answered here. If you want to write an app in MacRuby or Objective-C for OS X, the experience is essentially the same (though, of course, MacRuby has different command line flags for generating the final result, in this case the -deploy flag to MacRuby vs some linker invocation for ObjC). That said, nothing you write in MacRuby will run natively in Windows. Depending on the complexity of the app you have in mind, you may have to go to some cross-platform solution (like Unity) for that.

Check out Prism. It's not Ruby, but it does exactly what you describe and is open-source. One thing you'll to do is embed a web browser into a window, so look for libraries that do that. I'm assuming you'll use Cocoa for GUI since you're using MacRuby. In the end, the simplest way would be just have a window with web browser in it.

Related

Is there a way to package a Shoes Ruby App into an APK?

I am aware that I can package a Shoes Ruby app into a dmg, exe, and other Linux formats, but can I do an APK? I'm hoping to run a Shoes app on my Samsung Galaxy. Is there some gem or some long process to achieve this? Any method will do.
Very likely the answer is no and even if someone somehow built a way it probably won't be something you will want to use. GUI programming between desktop and mobile is very different and you will usually have to use different tools for both. The best you will get is writing a GUI using HTML/CSS/JS and using tools to get those running on mobile and desktop.

Deploying Ruby-Tk app on OS X

I'm looking for a straightforward way to deploy a standalone Ruby-Tk desktop app on OS X. All existing options for deploying desktop Ruby GUI apps on the Mac (e.g. standaloneify.rb) assume that you are using RubyCocoa or MacRuby, and are tightly bound to Xcode/Interface Builder project structure; or, alternatively, that you are wrapping a simple script via Platypus that does not involve deploying the entire Ruby runtime. None of the other existing options that I've found--rubyscript2exe, ocra, crate--support the Mac and/or support Ruby 1.9.
I'm hoping that someone can point me to a shell script or Ruby script that does the following:
Tracks all dependencies/gems in an app.
Copies the Ruby interpreter and dependencies into an application bundle.
Runs install_name_tool on the Ruby interpreter and all dylibs to make them portable.
The application bundle can either be something created by Platypus, use a Cocoa stub launcher, or even a shell script--I know how to handle those. The problem I'm having is getting the Ruby runtime wrapped in a portable way.
There's a rakefile at http://weft-qda.rubyforge.org/svn/trunk/weft-qda/rake/rake_osx.rb that encompasses the tasks that I'm looking to achieve, but this rakefile is part of a larger build structure that I can't get running on my Mac. I'm not familiar enough with rakefile structure to refactor this into a simple script that I can run, either via "ruby rake_osx.rb" or even "rake".
If someone can suggest to me how to modify this rakefile to run independently, or point me to another example project, or even share some code, I would be grateful. The project I am working on is better suited for Ruby than Python (better library support in Ruby), but I am not going to invest time in it if deployment won't work. (Python has a much richer tradition of deployment tools than Ruby, something I'v never quite understood.)
This is a bit late after the fact, but in classic fashion, since I could not find a desktop app deployment tool for Ruby-Tk on the Mac, I wrote my own:
ruby2app
ruby2app is a simple command-line tool, inspired by similar Mac tools like py2app for Python, that bundles a Ruby script with the Ruby runtime into a standalone Mac application. It reads a basic configuration file to find the appropriate Ruby installation, compiles a small C program that embeds the Ruby interpreter, copies the entire Ruby installation into the application bundle, and re-links the relevant libraries with the main executable.
It attempts to provide for the Mac what ocra and exerb provide for Windows. Hopefully this will be of use to others.

Running Sinatra within a MacRuby app

I'm new to MacRuby with Xcode but I have what I think (hope) is a simple question. I have a small Ruby Sinatra web app that I want to package as a Mac OS packaged application (.app). The application (however it is packaged) is used to read a specific plist file that is apart of Mac OS X Server and display the results through a specific web port in a browser. I don't know if MacRuby is the way to go, but all I need is a simple GUI that starts and stops the Sinatra web app so that users don't have to fuss with the command line (and hopefully without having to install gems, etc). I'm starting to figure out some of the basics of MacRuby and Xcode 4 but I'm not sure where to place the Sinatra ruby file within the Xcode project or how to start it.
I do know how to run a bash command start the ruby server within the application path but not sure if that's the best way or where to actually put the ruby file.
Please forgive my lack of knowledge of desktop developmentā€”I really only work in the web world. If I can elaborate on any points, let me know.
Control Tower may be your solution:
https://github.com/MacRuby/ControlTower
Part of the macruby project, it does basically what you wish. It's still very new & needs work, but It does function. I have been able to get it to work with sinatra for some test apps but I have yet to try to get any of my actually apps to run thru it (As I am still learning myself)

How do you port a Cocoa/Mac application to Windows?

How do you port a Cocoa/Mac application to Windows? I mean how would you go about it? Assume the app was written with Objective-C and Cocoa, there's nothing fancy going on, no "engine" that could be factored out, etc.
Rewrite from scratch? I don't think there will be huge overlaps between the Mac and Windows codebases, right?
I have doubts about cocotron.
Its not clear from the cocotron website that cocotron is actually production ready yet. Id suspect that it would be possible to start new app development and use cocotron constantly to maintain and test windows builds on the go.
But to retrofit it into an existing project might be a much larger task. There are also no alternatives to cocotron - other than perhaps gnustep.
The practical approach to cross platform development involves developing the non gui components of your application, once, in C or C++. And then using a cross platform GUI library like QT - which is VERY good at generating and using native UI where possible or faking it where not. Please DO go to qt.nokia.com and download the latest build of QTCreator for windows and mac - See how the same QT application looks and feels very convincingly native on both platforms.
If QT doesn't provide a native enough solution, then you need to develop your GUI twice :- once in Cocoa, and once in Win32. The cocoa GUI would be in objective C of course, the Win32 GUI in C/C++.
Your non gui application code would - written in c++ - not be able to call Objective-C directly, but its not hard to write shim classes, implemented in .mm files - the provide a c++ interface, and wrap access to an objective c object or class.
You are also going to have to come up with an alternative to CoreData on windows - perhaps sqlite? Given that XCode has integrated support for the sqlite framework, and testing multiple code paths is, well, more work - perhaps dropping CoreData in favor of a common layer is a better approach?
The problem with Objective C is its very poor support on any platform that is not OS X. You can attempt to use the Cocotron, but I wouldn't consider it production ready yet.
For portability, a re-write is in order. With judicious use of standard C or C++ for the "core" of the application, you could still implement platform specific GUI code. If you don't like maintaining two GUIs, you can also try a toolkit such as Qt
Depending on which objects and framework you are using for your cocoa app, you might be able to get away with using gnustep, although the end result will probably look very weird to windows users, and the development environment might be a bit difficult to setup at first.
Are you aware of Cocotron? It looks like the project may have gone stale, but it's a good starting point anyway. It's a project to port Core APIs.
If your application is not cleanly separated (ie: a la MVC) then the only solution is a rewrite, I think.

Programming language for GUI compilable to native binary

I need to write an app that reads a config file with info on the menu bars it needs to create.
Normally, I'd just use java, but I need the application to have the least run-time dependencies possible, this includes not forcing the user to download anything, even JRE, let alone something like NET Framework.
So I need something that can compile to an EXE (windows only for now), and that will allow me to CODE the GUI, so I can dynamically create it from my config.
BTW: something like C++ is a bit too low level, all I need is to create menus, and display HTMLs in a panel.
How about wxPython together with py2exe?
There is a nice tutorial on how to do it here.
If Java's too high-level and C++ too low-level, there ins't much in-between. Maybe Delphi?
I wouldn't totally write off using Java and/or Python for a few reasons.
1) py2exe can compile your Python code to an exe.
2) GCJ can compile your Java code to an exe.
Delphi is best chose for you. Because Delphi compile source code into native x86.
Unless you have serious reasons to avoid interpreted languages, I would suggest you better look into ways of packaging or compiling interpreted scripts because doing this will likely reduce your learning and development time.
I would write a simple GUI in Tcl/Tk, and then package it as a Starpack.
ActiveState provides a distribution (ActiveTCL) and a decent editor (Komodo Edit), and it is fairly easy to get simple GUIs going with Tk. Check out TkDocs for some hand holding.
Once you're done, you can package your code, a Tcl runtime, a database, and a virtual filesystem, all into a single executable that you can easily distribute.
Earwicker is right. You can use HTA:
http://www.interclasse.com/scripts/htanotepad.php
But if you know C++, then creating this type of an application is actually very easy with Visual C++. Use MFC, and statically link everything. You can draw the menu in the resource editor, and attach events to the menu items. I wouldn't use HTML if I were you. Just use regular Windows controls. But if you're really set on using HTML, you can embed a Browser control in the formview.
Have you considered D ? It has a syntax that is like a mixture of Java, C++ and Python with the ability to make native windows apps. The tutorials on dprogramming.com are great to get up and going with the language. For quick GUIs you'd be interested in The D Forms Library and the Entice Designer.
Here are some short video tutorials to get up and running with Entice.
Alternatively, have you tried Qt & Qt Creator? It takes a lot of the hair pulling out of C++ Programming and it's also cross-platform.
You say:
all I need is to create menus, and
display HTMLs in a panel.
A lot like a Web browser, then. If it's going to run on Windows, then the user has IE. Why not use IE to do all the work for you?
You can make something a lot like an .exe with IE, called an .hta:
http://msdn.microsoft.com/en-us/library/ms536496(VS.85).aspx

Resources