[MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby

terl tvmoore at mac.com
Tue Aug 2 15:24:36 PDT 2011


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 at caiochassot.com> wrote:
>> On Tue, Aug 2, 2011 at 04:26, Terry Moore <tvmoore at 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 at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list