Skip to content

Instantly share code, notes, and snippets.

@kch

kch/foo.rb Secret

Created August 2, 2011 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kch/960048c72a9b55db40b3 to your computer and use it in GitHub Desktop.
Save kch/960048c72a9b55db40b3 to your computer and use it in GitHub Desktop.
works in macirb, fails in macruby
#!/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)}"
@kch
Copy link
Author

kch commented Aug 2, 2011

$ uname -a
Darwin meaningless.local 11.0.0 Darwin Kernel Version 11.0.0: Sat Jun 18 12:56:35 PDT 2011; root:xnu-1699.22.73~1/RELEASE_X86_64 x86_64

$ macruby -v
MacRuby 0.11 (ruby 1.9.2) [universal-darwin10.0, x86_64]

@kch
Copy link
Author

kch commented Aug 2, 2011

I know, right. mv $@ ~/.Trash

@kch
Copy link
Author

kch commented Aug 2, 2011

$ macirb foo.rb 
# … irb output elided 
Should be false: false

$ macruby foo.rb 
Should be false: true

@kch
Copy link
Author

kch commented Aug 2, 2011

Fails in nush script, runs in nush interactive:

#!/usr/bin/env nush
((NSWorkspace sharedWorkspace) 
 recycleURLs:(array (NSURL fileURLWithPath: "/Users/kch/Desktop/a.txt"))
 completionHandler:nil)

@kch
Copy link
Author

kch commented Aug 2, 2011

Fails in ObjC, too:

// clang -o bar bar.m -fobjc-gc-only -framework Cocoa
#import <Cocoa/Cocoa.h>

int main (int argc, const char * argv[]) {
  NSString *path = @"/Users/kch/Desktop/a.txt";
  NSURL    *url  = [NSURL fileURLWithPath:path];
  NSArray  *urls = [NSArray arrayWithObject:url];
  [[NSWorkspace sharedWorkspace] recycleURLs:urls completionHandler:nil];
  // sleep(1); // <- fails unless sleep is present
  return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment