[MacRuby-devel] 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.
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
> 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? ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
On Tue, Aug 2, 2011 at 03:01, Caio Chassot 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… ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
On Tue, Aug 2, 2011 at 03:24, Caio Chassot 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 [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
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 wrote: > On Tue, Aug 2, 2011 at 03:24, Caio Chassot 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 > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
On Tue, Aug 2, 2011 at 04:26, Terry Moore 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`. :/ ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
On Tue, Aug 2, 2011 at 04:55, Caio Chassot wrote: > On Tue, Aug 2, 2011 at 04:26, Terry Moore 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 [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Small WebView commandline script
I've been doing some HTML scraping with Mechanize recently and I figured I could use a small tool that opens up a small WebView and reads HTML fragments from STDIN. Here's what I came up with: https://gist.github.com/1121174 There are a couple of things wrong with it that I chalk up to noobishness (and the fact that I usually start with an application template in XCode and use Objective-C), that I could use some help on: 1) Despite passing in Closable and Resizeable, the window doesn't seem to do either. Also I can never get focus or scroll. Does the window need to be open in a different thread? Have a window controller? If so, what's the best way to do that? (Most of the tutorials I've seen are either full Applications or minimal scripts with no UI.) 2) Is there anyway to embed/access a web developer console like the one in Safari? Thanks. -- –Andrew O'Brien ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] NSWorkspace.sharedWorkspace.recycleURLs:completionHandler doing nothing under macruby
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 wrote:
>> On Tue, Aug 2, 2011 at 04:26, Terry Moore 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
> [email protected]
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
___
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Small WebView commandline script
1) NSApplication.sharedApplication.activationPolicy = NSApplicationActivationPolicyRegular NSApplication.sharedApplication.activateIgnoringOtherApps(true) That will give your CLI app focus. 2) No idea, the inspector is just html + js, so you should be able to port it. You can also use the webkit scripting bridge to get Ruby <=> JS and create a simple editor in MacRuby. (I have a demo somewhere where I show how to write a HTML 5 game controlled by a bluetooth PS3 controller. It shows how to easily use the webkit bridge. - Matt On Tue, Aug 2, 2011 at 1:58 PM, Andrew O'Brien wrote: > I've been doing some HTML scraping with Mechanize recently and I figured I > could use a small tool that opens up a small WebView and reads HTML > fragments from STDIN. Here's what I came up with: > > https://gist.github.com/1121174 > > There are a couple of things wrong with it that I chalk up to noobishness > (and the fact that I usually start with an application template in XCode and > use Objective-C), that I could use some help on: > > 1) Despite passing in Closable and Resizeable, the window doesn't seem to > do either. Also I can never get focus or scroll. Does the window need to be > open in a different thread? Have a window controller? If so, what's the best > way to do that? (Most of the tutorials I've seen are either full > Applications or minimal scripts with no UI.) > 2) Is there anyway to embed/access a web developer console like the one in > Safari? > > Thanks. > > -- > –Andrew O'Brien > > > ___ > MacRuby-devel mailing list > [email protected] > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel > > ___ MacRuby-devel mailing list [email protected] http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
