NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
NSWorkspace.sharedWorkspace.recycleURLs:completionHandler: fails for me when run via normal macruby, yet works in macirb. Sample code: #!/usr/bin/env macruby framework 'Cocoa' path = "#{ENV['HOME']}/Desktop/Y-U-NO-TRASH-ME-MACRUBY.txt" system "touch #{path}" url = NSURL.fileURLWithPath(path) urls = [url] NSWorkspace.sharedWorkspace.recycleURLs(urls, completionHandler:nil) puts "Should be false: #{File.exists?(path)}" (or: https://gist.github.com/960048c72a9b55db40b3) Output from running it: $ macirb foo.rb # … irb output elided Should be false: false $ macruby foo.rb Should be false: true Running on public release of Lion, clean install, with latest macruby nightly, bridgesupport preview 3. The equivalent code works fine in Nu.
The equivalent code works fine in Nu.
Oh, actually I went ahead and tested again in nu, this time both interactively under nush, and as a script with nush in the shebang line. Interactively it works, as shebang it fails silently, same as macruby/irb. Weird. So maybe there's something I don't understand about NSWorkspace?
On Tue, Aug 2, 2011 at 03:01, Caio Chassot <lists@caiochassot.com> wrote:
Weird. So maybe there's something I don't understand about NSWorkspace?
Some meh progress: adding sleep 0.1 before the puts sets things right. At this point I'm sure this is not a MacRuby bug, just some Cocoa weirdness. I'd love to understand exactly what the hell is going on, if anyone knows…
On Tue, Aug 2, 2011 at 03:24, Caio Chassot <lists@caiochassot.com> wrote:
At this point I'm sure this is not a MacRuby bug, just some Cocoa weirdness. I'd love to understand exactly what the hell is going on, if anyone knows…
…and to back that, it fails in ObjC too, and adding a sleep there fixes it, too.
Sounds like an asynchronous issue. Try adding a completion selector and calling nsrunloop. Terry Moore On 2/08/2011, at 10:56 PM, Caio Chassot <lists@caiochassot.com> wrote:
On Tue, Aug 2, 2011 at 03:24, Caio Chassot <lists@caiochassot.com> wrote:
At this point I'm sure this is not a MacRuby bug, just some Cocoa weirdness. I'd love to understand exactly what the hell is going on, if anyone knows…
…and to back that, it fails in ObjC too, and adding a sleep there fixes it, too. _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Tue, Aug 2, 2011 at 04:26, Terry Moore <tvmoore@mac.com> wrote:
Sounds like an asynchronous issue. Try adding a completion selector and calling nsrunloop.
Tried both, no dice. @jacknutting mostly nails it:
core problem is that AppKit classes are really meant for use in a full app (w/ GUI). Foundation OK in scripts. NSFileManager?
(https://twitter.com/jacknutting/status/98353849055715330) The length of the page here leads me to believe cocoa sucks at trashing: http://www.cocoadev.com/index.pl?MoveToTrash The icing on the cake is that this is likely dead simple to do with… wait for it… AppleScript. Well, rb-appscript anyway. Or ScriptingBridge and the Finder. I'd `mv $@ ~/.Trash`, but "Trash is complicated. Handles name clashes, different behaviour for mounted volumes, restores to original location." (https://twitter.com/kch/status/98359569553690624) So, well… `rm -rf`. :/
On Tue, Aug 2, 2011 at 04:55, Caio Chassot <lists@caiochassot.com> wrote:
On Tue, Aug 2, 2011 at 04:26, Terry Moore <tvmoore@mac.com> wrote:
Sounds like an asynchronous issue. Try adding a completion selector and calling nsrunloop. Tried both, no dice.
Side talk for the curious: http://tweetlibrary.com/kch/trash
Caio this works fine for me.... os x 10.7, MacRuby 0.11 (ruby 1.9.2) [universal-darwin10.0, x86_64] #!/usr/bin/env macruby framework 'Cocoa' class Trash_Files def initialize() @error = Pointer.new(:object) @path = "#{ENV['HOME']}/Desktop/Y-U-NO-TRASH-ME-MACRUBY.txt" system "touch #{@path}" end def start #This methods may show a progress indicator, or other user interface elements, at AppKit's discretion. #In Mac OS X 10.6, this method require that the main run loop be run in a common mode. @call_back = lambda do |urls,err| puts "#{err[0].inspect}" if err urls.each{ |ar| ar.each { |r| puts "url = '#{r.path}'"}} exit end NSWorkspace.sharedWorkspace.recycleURLs([NSURL.fileURLWithPath(@path)], completionHandler:@call_back) NSRunLoop.currentRunLoop.run end end t = Trash_Files.new.start Of course you may NOT want to call exit...maybe use a thread and or use RunUntilDate.... or something along those lines. Terry On 3/08/2011, at 12:11 AM, Caio Chassot wrote:
On Tue, Aug 2, 2011 at 04:55, Caio Chassot <lists@caiochassot.com> wrote:
On Tue, Aug 2, 2011 at 04:26, Terry Moore <tvmoore@mac.com> wrote:
Sounds like an asynchronous issue. Try adding a completion selector and calling nsrunloop. Tried both, no dice.
Side talk for the curious: http://tweetlibrary.com/kch/trash _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (3)
-
Caio Chassot
-
terl
-
Terry Moore