Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.