[MacRuby-devel] [MacRuby] #821: uncached ObjC stub - Abort trap

B. Ohr jazzbox at 7zz.de
Wed Aug 4 02:21:49 PDT 2010


Hi,

just for those who are interested, I translated John Grubers ‚open urls in safari tabs‘-script to pure MacRuby.

The rather complex regular expression for detecting URLs in text is working fine in MacRuby!

(AOT-compilation does not work yet, see ticket #821)

-- Bernd


#!/usr/local/bin/macruby

# MacRuby version of http://daringfireball.net/2010/08/open_urls_in_safari_tabs

begin
  framework 'Cocoa'
rescue
  NSUTF8StringEncoding = 4    # defining constants by hand for AOT-compiled version
  NSWorkspaceLaunchWithoutActivation = 512
end

regexp = Regexp.new '(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'
 
urls = STDIN.read.scan(regexp).uniq.map do |m| 
  NSURL.URLWithString(m.first.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding))
end.compact

NSWorkspace.sharedWorkspace.openURLs(urls,
      withAppBundleIdentifier:nil,
      options:NSWorkspaceLaunchWithoutActivation,
      additionalEventParamDescriptor:nil,
      launchIdentifiers:nil)
      



More information about the MacRuby-devel mailing list