Including a Helper Application in RubyMotion app

325 views
Skip to first unread message

Jonas Bruun Nielsen

unread,
Oct 25, 2013, 2:55:31 PM10/25/13
to rubym...@googlegroups.com
Hi everyone

I love RubyMotion passionately. But I must admit, two things often makes me feel like a helpless idiot. Configuring build settings and vendoring third-party libs. 

In this case I'm building a dockless menu bar app that should be able to start at login. To comply with App Sandboxing, Apple requires a helper application to be contained in the app bundle.

The process (with Xcode) is described in fine detail in this blog post. But I have no idea where to start in RubyMotion. What the heck do I do?

Any help is so very, very appreciated!

Thanks,
Jonas

Ashish Upadhyay

unread,
Oct 25, 2013, 5:08:32 PM10/25/13
to rubym...@googlegroups.com
I really dont think that the creators of RM are interested in helping out openly ! ..

May be they will blame xcode for the same.

Eloy Durán

unread,
Oct 25, 2013, 6:56:50 PM10/25/13
to rubym...@googlegroups.com
I feel your pain, these types of things always tend to be hairy, regardless of using RubyMotion or objc/Xcode. I haven’t had to do this myself yet, but I’ll try to give a high level overview of what –as I understand it– you need to do.

There are two apps of importance:

1. The ‘helper’ application. This application is nothing more than a ‘boot’ application for the actual app, a trampoline if you will. It does this by simply calling -[NSWorkspace launchApplication:] once the application has started and passing in the main app's bundle path. This application has to be at a specific location inside the main app, more on that later. This app might probably exit after launching the main app, but the blog post doesn’t mention this explicitly, so you’ll need to verify this.

2. The actual dockless status bar app. Besides the normal work you want this app to do, it is also responsible for registering the ‘boot helper’ application with Launch Services. You do this by using the code that the blog post mentions that’s inside the setStartAtLogin:enabled: method. In that method they register the location of the ‘boot helper’ application (the path inside the main app) and then set it to be a ‘login item’. On the next boot of the system the helper application will be started and launch the main dockless status bar app.

The two build phase steps are:

1. As RubyMotion only builds one app per project you’ll have to create two projects, one for each app. Simply build the ‘boot helper’ app first and use the build product in the main project.

2. The ‘boot helper’ application has to be placed in another path than where normal resources would be, this is the path alluded to before. To do this I suggest that you place it in, for instance, a HelperApp subdir and use the power of Ruby to hook copying this app into the build process. Here’s an example that you can copy into your Rakefile:

class Motion::Project::App
class << self
#
# The original `build' method can be found here:
# https://github.com/HipByte/RubyMotion/blob/master/lib/motion/project/app.rb#L75-L77
#
alias_method :build_before_copy_helper, :build
def build(platform, options = {})
# First let the normal `build' method perform its work.
build_before_copy_helper(platform, options)
# Now the app is built, but not codesigned yet.

destination = File.join(config.app_bundle(platform), 'Library/LoginItems')
info 'Create', destination
FileUtils.mkdir_p destination
info 'Copy', 'path/to/helper'
FileUtils.cp_r 'path/to/helper', destination
end
end
end

You can further inspect what the RubyMotion build process does by either checking out the code here: https://github.com/HipByte/RubyMotion/tree/master/lib/motion, or simply on your local machine in /Library/RubyMotion/lib.

HTH
> --
> You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubymotion/3d2dc51c-72ef-40a8-b809-24b1a20dc750%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jonas Bruun Nielsen

unread,
Oct 26, 2013, 2:41:41 PM10/26/13
to rubym...@googlegroups.com
Eloy, thank you so very, very much! That was incredibly helpful. It was exactly the input I needed to get things working. Please let me know, if I can return the favor somehow @jonasnielsen.

I created a small RubyMotion template and wrote a quick guide for others who wants to achieve this: Dockless RubyMotion menubar app with start at login

Thanks!

Joe Fiorini

unread,
Oct 26, 2013, 3:38:38 PM10/26/13
to rubym...@googlegroups.com
Jonas,

Since you're building a menu bar app, I wanted to let you know about my gem, Drink Menu. It makes setting up menus that respond to user interaction much more painless. FWIW, I have a menu bar app that uses it in the app store now. http://github.com/joefiorini/drink-menu

Good luck on your app!
- Joe

Jonas Bruun Nielsen

unread,
Oct 27, 2013, 5:21:44 AM10/27/13
to rubym...@googlegroups.com
Thanks Joe. Drink Menu looks cool. My app displays a popover instead though.


--
You received this message because you are subscribed to a topic in the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubymotion/apU9jpfI1R0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubymotion+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubymotion/28e15a6c-6614-437f-be83-aea7bdca4d9b%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Mvh
Jonas

Eloy Durán

unread,
Oct 28, 2013, 7:26:47 AM10/28/13
to rubym...@googlegroups.com
Glad to hear it helped and thanks for sharing the guide! Please let us know if you tweet a link to your guide so we can retweet it.

Jonas Bruun Nielsen

unread,
Oct 31, 2013, 4:45:05 PM10/31/13
to rubym...@googlegroups.com
Thanks Eloy, I definitely will. But before I do I think I need to make a some adjustments to the part that includes the helper app in the build process. It's described under step 3. here.

In particular, I'm pretty sure the helper app is not being code signed. I tried building the helper app with for release, but the task fails:
$ rake build:release
     Build ./build/MacOSX-10.8-Release
   Compile ./app/app_delegate.rb
./build/MacOSX-10.8-Release/objs/Users/jonasbruunnielsen/OSXApps/motion-s/S-app-launcher/app/app_delegate.rb.i386.s:1069:2: error: invalid instruction mnemonic 'cvtsi2sdl'
 cvtsi2sdl %ebx, %xmm0
 ^~~~~~~~~
./build/MacOSX-10.8-Release/objs/Users/jonasbruunnielsen/OSXApps/motion-s/S-app-launcher/app/app_delegate.rb.i386.s:1086:2: error: invalid instruction mnemonic 'cvtsi2sdl'
 cvtsi2sdl %eax, %xmm1
 ^~~~~~~~~
(…)
rake aborted!
Command failed with status (1): [/usr/bin/clang -fexceptions -c -arch i386 ...]
/Library/RubyMotion/lib/motion/project/builder.rb:140:in `block (2 levels) in build'
/Library/RubyMotion/lib/motion/project/builder.rb:111:in `each'
/Library/RubyMotion/lib/motion/project/builder.rb:111:in `block in build'
/Library/RubyMotion/lib/motion/project/builder.rb:534:in `call'
/Library/RubyMotion/lib/motion/project/builder.rb:534:in `block (2 levels) in initialize'
Tasks: TOP => build:release

The app is really thin so I'm pretty puzzled why this is happening. Any ideas?

Thanks,
Jonas

Eloy Durán

unread,
Nov 4, 2013, 5:39:03 AM11/4/13
to rubym...@googlegroups.com
No immediately. Can you please create a support ticket for this?

Eloy Durán

unread,
Nov 4, 2013, 5:50:05 AM11/4/13
to rubym...@googlegroups.com
s/No immediately/Not immediately/ :)

Mark Rickert

unread,
Nov 4, 2013, 7:14:13 PM11/4/13
to rubym...@googlegroups.com
I'm working on a mac app with a helper app to launch on startup based on Jonas's template, so it would be great to get the codesigning issues fixed :)

+1 for bug report, thought I haven't tried codesigning the two apps yet (not there in the dev process yet)

-Mark

Jonas Bruun Nielsen

unread,
Nov 5, 2013, 11:24:01 AM11/5/13
to rubym...@googlegroups.com
Hi Mark

I just tested with the latest RubyMotion 2.14 on Mavericks and it appears to work. Only few modifications are needed. I'll keep you posted.

Cheers Jonas


--
You received this message because you are subscribed to a topic in the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubymotion/apU9jpfI1R0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubymotion+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubymotion/b05a7b0f-ec66-48b9-acea-1e31e40f5b49%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Mvh
Jonas

holger sindbæk

unread,
Dec 28, 2013, 2:54:27 PM12/28/13
to rubym...@googlegroups.com
What was the end of the story with this one? Did we get the helper app to work?

Jonas Bruun Nielsen

unread,
Dec 31, 2013, 6:14:19 AM12/31/13
to rubym...@googlegroups.com
Yes, helper apps are working. Your best reference may be Mark's Hacker-Bar app that he open sourced: https://github.com/MohawkApps/Hacker-Bar

This slightly out of date blog post explain some of the details: https://coderwall.com/p/cae2eq


Mark Rickert

unread,
Dec 31, 2013, 1:00:48 PM12/31/13
to rubym...@googlegroups.com
Thanks for the shout-out, Jonas :)

Specifically, check out my makefile and the scripts directory. There you can see there I'm compiling each one right after another.

The most important part is the Motion::Project::App overriding in the main rakefile: https://github.com/MohawkApps/Hacker-Bar/blob/master/Rakefile#L44-L68

Good luck and let us know if you need any help getting it working. Hacker Bar is in the Mac App Store with this helper app and is working beautifully.

-Mark
Reply all
Reply to author
Forward
0 new messages