Skip to content

Instantly share code, notes, and snippets.

@chamons
Created April 20, 2015 16:33
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 chamons/05bea0e3a235e195d305 to your computer and use it in GitHub Desktop.
Save chamons/05bea0e3a235e195d305 to your computer and use it in GitHub Desktop.
public static class NSWorkspacePatch
{
static readonly IntPtr selOpenURLsWithAppBundleIdentifierOptionsAdditionalEventParamDescriptorLaunchIdentifiers_Handle = Selector.GetHandle ("openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:");
public static bool OpenUrls (this NSWorkspace ws, NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor)
{
global::MonoMac.AppKit.NSApplication.EnsureUIThread ();
if (urls == null)
throw new ArgumentNullException ("urls");
if (bundleIdentifier == null)
throw new ArgumentNullException ("bundleIdentifier");
if (descriptor == null)
throw new ArgumentNullException ("descriptor");
var nsa_urls = NSArray.FromNSObjects (urls);
var nsbundleIdentifier = NSString.CreateNative (bundleIdentifier);
bool ret = global::MonoMac.ObjCRuntime.Messaging.bool_objc_msgSend_IntPtr_IntPtr_int_IntPtr_IntPtr
(ws.Handle, selOpenURLsWithAppBundleIdentifierOptionsAdditionalEventParamDescriptorLaunchIdentifiers_Handle,
nsa_urls.Handle, nsbundleIdentifier, (int)options, descriptor.Handle, IntPtr.Zero);
nsa_urls.Dispose ();
NSString.ReleaseNative (nsbundleIdentifier);
return ret;
}
}
public partial class AppDelegate : NSApplicationDelegate
{
MainWindowController mainWindowController;
public override void DidFinishLaunching (NSNotification notification)
{
mainWindowController = new MainWindowController ();
mainWindowController.Window.MakeKeyAndOrderFront (this);
NSWorkspace.SharedWorkspace.OpenUrls (new [] { new NSUrl ("https://www.google.com/") },
"com.Apple.Safari", NSWorkspaceLaunchOptions.Default, NSAppleEventDescriptor.NullDescriptor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment