0

Trying to whip up something quick and dirty that mass renames and converts files, and having a rubymotion license I thought why not use it to make a simple app that you can drag and drop instead of some batch file.

However I am having trouble detecting the drag event, can't seem to find information about how to do this in rubymotion, I've only used rubymotion to do iOS apps, and find myself lost.

Any help would be appreciated.

1

2 Answers 2

1

Have you started on any Cocoa tutorials? Anything written in Objective-C can be ported easily. I would start here: Drag and Drop Programming (developer.apple.com)

If you want to support dragging onto the dock icon, you'll need to modify the project's supported document types, and I'm not sure how to do this (check rake config, it might give a clue). You'll eventually need to implement this method, too:

def application(sender, openFile: path)
  # sender is an NSApplication, path is NSString
  true  # or false
end
3
  • I forgot that app.info_plist is available, so you should be able to add the document types there. The XML key is CFBundleDocumentTypes and CFBundleTypeExtensions, e.g. app.info_plist['CFBundleDocumentTypes'] = [{'CFBundleTypeExtensions'=>['txt'],'CFBundleTypeRole'=>'Editor'}]
    – colinta
    Jan 7, 2015 at 17:36
  • I got those keys from here: qt-project.org/doc/note_revisions/351/659/view
    – colinta
    Jan 8, 2015 at 16:57
  • Thank you for the advice! still having difficulty translating obj-c to ruby, I know it should be high-priority to be able to do that since most of the info for OSX and iOS would be in Obj-C.
    – Saifis
    Jan 9, 2015 at 4:50
0

You need to add something like :

app.info_plist['CFBundleDocumentTypes'] = [
  {'CFBundleTypeRole': 'Viewer', 'CFBundleTypeExtensions': ['mp4','m4v','avi','*'] } ,
  {'CFBundleTypeRole': 'Editor', 'CFBundleTypeExtensions': ['txt'] }
]

to the setup block in the Rakefile

And add the following method to the AppDelegate class in app_delegate.rb

def application(sender, openFile: path)
  true
end

Do a rake clean before you do rake build and you should be good to go.

Note that the application method gets called for each file that you drop onto the Application icon. path contains a string of the dropped files path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.