Would anyone be able to give me a hint on how to get the following objective-c code working with macruby. The code uses spotlight to extract metadata from a file. MDItemRef inspectedRef = MDItemCreate(kCFAllocatorDefault,(CFStringRef)path); CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef); NSLog(@"%@", (NSArray*)attributeNames); I was hoping that including the 'CoreServices' framework would work, but no joy.
framework 'CoreServices' => true item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/test.jpg') NameError: uninitialized constant KCFAllocatorDefault from core:in `const_missing:' from (irb):2:in `<main>' from core:in `eval:' from core:in `evaluate:' -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - IMAP accessible web-mail
Hi Alan, I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http://bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime. Laurent On Oct 27, 2009, at 5:13 PM, Alan Skipp wrote:
Would anyone be able to give me a hint on how to get the following objective-c code working with macruby. The code uses spotlight to extract metadata from a file.
MDItemRef inspectedRef = MDItemCreate(kCFAllocatorDefault,(CFStringRef)path); CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef);
NSLog(@"%@", (NSArray*)attributeNames);
I was hoping that including the 'CoreServices' framework would work, but no joy.
framework 'CoreServices' => true item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/ test.jpg') NameError: uninitialized constant KCFAllocatorDefault from core:in `const_missing:' from (irb):2:in `<main>' from core:in `eval:' from core:in `evaluate:' -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - IMAP accessible web-mail
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
I'm probably asking a really dumb question here - but I haven't used bridgesupport very much... Is there a reason why the constant in the example that fails starts with an upper case K, rather than keeping the lower case k given in the framework? Alli On Wednesday, October 28, 2009, at 01:31AM, "Laurent Sansonetti" <lsansonetti@apple.com> wrote:
Hi Alan,
I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http://bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
On Oct 27, 2009, at 5:13 PM, Alan Skipp wrote:
Would anyone be able to give me a hint on how to get the following objective-c code working with macruby. The code uses spotlight to extract metadata from a file.
MDItemRef inspectedRef = MDItemCreate(kCFAllocatorDefault,(CFStringRef)path); CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef);
NSLog(@"%@", (NSArray*)attributeNames);
I was hoping that including the 'CoreServices' framework would work, but no joy.
framework 'CoreServices' => true item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/ test.jpg') NameError: uninitialized constant KCFAllocatorDefault from core:in `const_missing:' from (irb):2:in `<main>' from core:in `eval:' from core:in `evaluate:' -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - IMAP accessible web-mail
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Not a dumb question at all, just one of those "Ruby-isms" that will take some adjusting to if you're coming from a C/C++/Obj-C background. In Ruby, Constants always start with a Capital letter. Therefore, all of the kFooBarBaz constants from Cocoa get translated as KFooBarBaz. Actually, that's got me thinking that we should maybe compile a list of the "cultural" differences between Obj-C and Ruby. I tried to sort of touch on it by pointing out Obj-C's tendency to CamelCase in place of Ruby's under_case, but I'm sure we can think of more of these transition-gotchas? - Josh On Oct 28, 2009, at 2:31 AM, Allison Newman wrote:
I'm probably asking a really dumb question here - but I haven't used bridgesupport very much... Is there a reason why the constant in the example that fails starts with an upper case K, rather than keeping the lower case k given in the framework?
Alli
On Wednesday, October 28, 2009, at 01:31AM, "Laurent Sansonetti" <lsansonetti@apple.com
wrote: Hi Alan,
I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http://bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
On Oct 27, 2009, at 5:13 PM, Alan Skipp wrote:
Would anyone be able to give me a hint on how to get the following objective-c code working with macruby. The code uses spotlight to extract metadata from a file.
MDItemRef inspectedRef = MDItemCreate(kCFAllocatorDefault,(CFStringRef)path); CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef);
NSLog(@"%@", (NSArray*)attributeNames);
I was hoping that including the 'CoreServices' framework would work, but no joy.
framework 'CoreServices' => true item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/ test.jpg') NameError: uninitialized constant KCFAllocatorDefault from core:in `const_missing:' from (irb):2:in `<main>' from core:in `eval:' from core:in `evaluate:' -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - IMAP accessible web-mail
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
I always assumed (with no direct evidence) that it was because in Ruby, constants have to start with an uppercase letter, and so to match various method signatures/types sent through BridgeSupport, constant types must be passed as constant types. Anyway for supported frameworks capitalising the constant always seems to work. BridgeSupport is an amazing piece of work in my opinion - worksk (and work very well) almost transparent to the developer. Actually am just assuming that the new Applescript methods use BridgeSupport? In which case BridgeSupport should just get better. HTH J On Oct 28, 2009, at 10:31 , Allison Newman wrote:
I'm probably asking a really dumb question here - but I haven't used bridgesupport very much... Is there a reason why the constant in the example that fails starts with an upper case K, rather than keeping the lower case k given in the framework?
Alli
On Wednesday, October 28, 2009, at 01:31AM, "Laurent Sansonetti" <lsansonetti@apple.com
wrote: Hi Alan,
I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http://bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
On Oct 27, 2009, at 5:13 PM, Alan Skipp wrote:
Would anyone be able to give me a hint on how to get the following objective-c code working with macruby. The code uses spotlight to extract metadata from a file.
MDItemRef inspectedRef = MDItemCreate(kCFAllocatorDefault,(CFStringRef)path); CFArrayRef attributeNames = MDItemCopyAttributeNames(inspectedRef);
NSLog(@"%@", (NSArray*)attributeNames);
I was hoping that including the 'CoreServices' framework would work, but no joy.
framework 'CoreServices' => true item = MDItemCreate(KCFAllocatorDefault, '/Users/alan/Desktop/ test.jpg') NameError: uninitialized constant KCFAllocatorDefault from core:in `const_missing:' from (irb):2:in `<main>' from core:in `eval:' from core:in `evaluate:' -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - IMAP accessible web-mail
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Laurent! On Oct 28, 2009, at 12:31 AM, Laurent Sansonetti wrote:
and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
Just a quick question. Imagine I have an Objective-C class that wraps that API. How can I then use it on a Macruby script? I probably have to compile it somewhere... Ruben
It's really simple, you just need to create an Objective-C class in your macruby application (header and implementation file). You can then use it in your ruby code without any hassle, it's great. For example, if you create an Objective-C class called 'MetaDataHelper', you can use it like this: helper = MetaDataHelper.new and call methods on it like any other ruby object, eg: metadata = helper.metadataForFile('/path/to/file/') I can post a code example later today, if that would be helpful. On Thu, 29 Oct 2009 09:27 +0000, "Ruben Fonseca" <ruben@0x82.com> wrote:
Hi Laurent!
On Oct 28, 2009, at 12:31 AM, Laurent Sansonetti wrote:
and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
Just a quick question. Imagine I have an Objective-C class that wraps that API. How can I then use it on a Macruby script? I probably have to compile it somewhere...
Ruben _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - One of many happy users: http://www.fastmail.fm/docs/quotes.html
Hi Alan! Thank you, that's very simple. However I'm still curious about the daily non-Xcode scripts. Image I want to write a macruby script that uses my Objective-C helper class. What's the easiest way to accomplish that outside XCode? Ruben On Oct 29, 2009, at 11:43 AM, Alan Skipp wrote:
It's really simple, you just need to create an Objective-C class in your macruby application (header and implementation file). You can then use it in your ruby code without any hassle, it's great. For example, if you create an Objective-C class called 'MetaDataHelper', you can use it like this: helper = MetaDataHelper.new
and call methods on it like any other ruby object, eg:
metadata = helper.metadataForFile('/path/to/file/')
I can post a code example later today, if that would be helpful.
Hi Ruben!
However I'm still curious about the daily non-Xcode scripts.
Image I want to write a macruby script that uses my Objective-C helper class. What's the easiest way to accomplish that outside XCode?
Ruben
Like you I played around a little with this issue. My current state is: If you have a MacRuby helper named foo.rb you can simply compile it like that macrubyc -V --arch x86_64 -C "foo.rb" -o "foo.rbo" This "foo.rbo" can be included in another script via require. If you have an ObjC you can compile it with gcc -c foo.m -o foo1.o -fobjc-gc but I failed to convert that foo1.o to an .rbo file. I tried some macrubyc options but none of them is working. On the other side making an .o out of a .rb is no problem: macrubyc -V --arch x86_64 -c "foo.rb" -o "foo.o" So I think, there is just one step missing in the options in macrubyc (or I am unable to read the source). Bernd
Hi Alan! Thank you, that's very simple. However I'm still curious about the daily non-Xcode scripts. Image I want to write a macruby script that uses my Objective-C helper class. What's the easiest way to accomplish that outside XCode? Ruben On Oct 29, 2009, at 11:43 AM, Alan Skipp wrote:
It's really simple, you just need to create an Objective-C class in your macruby application (header and implementation file). You can then use it in your ruby code without any hassle, it's great. For example, if you create an Objective-C class called 'MetaDataHelper', you can use it like this: helper = MetaDataHelper.new
and call methods on it like any other ruby object, eg:
metadata = helper.metadataForFile('/path/to/file/')
I can post a code example later today, if that would be helpful.
Hi Ruben, Using an Objective-C class in a MacRuby script is the first step in both recipes currently posted to the MacRuby website (http://www.macruby.org/documentation.html ). Your choices are either to add a "dummy" Init_foo{} function and make a foo.bundle from the class or compile the Objective-C files to a foo.framework and then either put the framework in a well known location (like /Library/Frameworks) or modify the DYLD_FRAMEWORK_PATH before running your MacRuby script. If you want more details on wrapping C API, I am currently working on just such a project, and might be able to put together another recipe. What sort of information would you be looking for specifically? Is there a particular C API you'd be interested in seeing how to wrap? Finally, as to your later question, there actually *is* a MacRuby API for GCD currently in the 0.5 beta and nightly builds. Cheers, Josh On Oct 29, 2009, at 2:27 AM, Ruben Fonseca wrote:
Hi Laurent!
On Oct 28, 2009, at 12:31 AM, Laurent Sansonetti wrote:
and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
Just a quick question. Imagine I have an Objective-C class that wraps that API. How can I then use it on a Macruby script? I probably have to compile it somewhere...
Ruben _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi Josh! On Oct 29, 2009, at 5:48 PM, Josh Ballanco wrote:
Hi Ruben,
Using an Objective-C class in a MacRuby script is the first step in both recipes currently posted to the MacRuby website (http://www.macruby.org/documentation.html ). Your choices are either to add a "dummy" Init_foo{} function and make a foo.bundle from the class or compile the Objective-C files to a foo.framework and then either put the framework in a well known location (like /Library/Frameworks) or modify the DYLD_FRAMEWORK_PATH before running your MacRuby script.
Perfect! I read both recipes and it seems pretty easy :) Thank you!
If you want more details on wrapping C API, I am currently working on just such a project, and might be able to put together another recipe. What sort of information would you be looking for specifically? Is there a particular C API you'd be interested in seeing how to wrap?
Actually I was offering my time and help to create those wrappers :) I don't have any need for a particular C API right now...
Finally, as to your later question, there actually *is* a MacRuby API for GCD currently in the 0.5 beta and nightly builds.
Yes I know. That's why I've asked if it makes sense to include more wrappers to other C APIs into Macruby! Cheers Ruben
Hi Ruben, On Oct 29, 2009, at 11:07 AM, Ruben Fonseca wrote:
Finally, as to your later question, there actually *is* a MacRuby API for GCD currently in the 0.5 beta and nightly builds.
Yes I know. That's why I've asked if it makes sense to include more wrappers to other C APIs into Macruby!
Ah, my mistake. I misread your e-mail. So, actually the MacRuby GCD implementation isn't an Obj-C wrapper but rather a "baked-in" C wrapper around the C-level GCD API. As for whether it makes sense to include more wrappers, I would say "Yes! Definitely!". But, it's important to remember that these wrappers wouldn't just be MacRuby wrappers, they would also work as Obj-C wrappers for developers working with regular Obj-C Cocoa. So, if you'd like to get started, maybe the best thing to do would be to check with some Cocoa devs and see what C APIs they would like wrapped. Cheers, Josh
Hi Laurent. Just a quick question. On Oct 28, 2009, at 12:31 AM, Laurent Sansonetti wrote:
Hi Alan,
I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http:// bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
Does it make any sense to write wrappers to APIs not covered by BridgeSupport and bundle them in Macruby? (Isn't GCD such a case?). If that's the case, I can help with writing some of these wrappers. Ruben
Hi Ruben, On Oct 29, 2009, at 8:44 AM, Ruben Fonseca wrote:
Hi Laurent. Just a quick question.
On Oct 28, 2009, at 12:31 AM, Laurent Sansonetti wrote:
Hi Alan,
I'm afraid the MD* APIs haven't been covered by BridgeSupport yet, so it may not be possible to call it directly from MacRuby at this point. I would recommend to file a bug at http://bugreporter.apple.com so that we can consider this for a future Mac OS X release, and to wrap this C API into an Objective-C class that you can call from MacRuby in the meantime.
Laurent
Does it make any sense to write wrappers to APIs not covered by BridgeSupport and bundle them in Macruby? (Isn't GCD such a case?).
It would definitely be interesting to share the wrappers, but I don't know if bundling them as part of MacRuby is a good idea. If we start doing that we would have to make sure all wrappers are consistent. And these wrappers would be temporary, until a new version of Mac OS X comes out with the support. I guess that it's better if people share them on Github. We could have a list of them on the website so that people can easily find them. Thoughts? Laurent
Hi Lauren! On Oct 29, 2009, at 8:17 PM, Laurent Sansonetti wrote:
It would definitely be interesting to share the wrappers, but I don't know if bundling them as part of MacRuby is a good idea. If we start doing that we would have to make sure all wrappers are consistent. And these wrappers would be temporary, until a new version of Mac OS X comes out with the support.
I guess that it's better if people share them on Github. We could have a list of them on the website so that people can easily find them.
Thoughts?
Good to hear! I guess I agree with you. Since I'm new to this thing of adapting a C API to the Objective-C/ Ruby paradigm, I think I will try my first wrapper around the Spotlight API. Just a quick question: what should I do with C constants? Should I maintain them? Alias them? My plan is to make public version of the wrapper, ask for opinions, learn, rewrite, ..., profit :) Cheers Ruben
Hey, Forgive me that I haven't read the complete thread, so ignore this if it's not a possibility. But couldn't you use NSMetadataItem etc? Eloy On 30 okt 2009, at 13:12, Ruben Fonseca wrote:
Hi Lauren!
On Oct 29, 2009, at 8:17 PM, Laurent Sansonetti wrote:
It would definitely be interesting to share the wrappers, but I don't know if bundling them as part of MacRuby is a good idea. If we start doing that we would have to make sure all wrappers are consistent. And these wrappers would be temporary, until a new version of Mac OS X comes out with the support.
I guess that it's better if people share them on Github. We could have a list of them on the website so that people can easily find them.
Thoughts?
Good to hear! I guess I agree with you.
Since I'm new to this thing of adapting a C API to the Objective-C/ Ruby paradigm, I think I will try my first wrapper around the Spotlight API. Just a quick question: what should I do with C constants? Should I maintain them? Alias them?
My plan is to make public version of the wrapper, ask for opinions, learn, rewrite, ..., profit :)
Cheers Ruben _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hey Eloy! On Oct 30, 2009, at 9:50 PM, Eloy Duran wrote:
Hey,
Forgive me that I haven't read the complete thread, so ignore this if it's not a possibility. But couldn't you use NSMetadataItem etc?
You know what this silence means don't you? :) I had no idea about NSMetadataItem.. However, my question remains, is there a C API that would benefit from a wrapper so it can be easily used in macruby? Ruben
I was also unaware of NSMetadataItem, but it seems that the only way of acquiring such an object is from the result of a spotlight search. There doesn't seem to be a way of creating an NSMetadataItem from a file path or url, as you can do with MDItemRef – though there is a distinct possibility that I am overlooking something. On Wed, 04 Nov 2009 10:16 +0000, "Ruben Fonseca" <ruben@0x82.com> wrote:
Hey Eloy!
On Oct 30, 2009, at 9:50 PM, Eloy Duran wrote:
Hey,
Forgive me that I haven't read the complete thread, so ignore this if it's not a possibility. But couldn't you use NSMetadataItem etc?
You know what this silence means don't you? :) I had no idea about NSMetadataItem..
However, my question remains, is there a C API that would benefit from a wrapper so it can be easily used in macruby?
Ruben _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel -- Alan Skipp al_skipp@fastmail.fm
-- http://www.fastmail.fm - Does exactly what it says on the tin
participants (9)
-
Alan Skipp
-
Allison Newman
-
B. Ohr
-
Eloy Duran
-
John Shea
-
Josh Ballanco
-
Joshua Ballanco
-
Laurent Sansonetti
-
Ruben Fonseca