Example #1
0
        public static int LaunchApplicationForPath(string path, string[] args, bool activate = true)
        {
            var options       = new NSWorkspaceLaunchOptions();
            var arguments     = NSArray.FromObjects(args);
            var configuration = NSDictionary.FromObjectAndKey(arguments, NSWorkspaceLaunchConfigurationArguments);
            var url           = new NSUrl(path, false);

            NSError error = new NSError();

#if MONOMAC
            var app = NSWorkspace.SharedWorkspace.LaunchApplication(url, options, configuration, error);
#else
            var app = NSWorkspace.SharedWorkspace.OpenURL(url, options, configuration, out error);
#endif
            if (error != null)
            {
                throw new ApplicationException("NSWorkspace failed to open URL: " + url);
            }

            if (app == null)
            {
                return(0);
            }

            if (activate)
            {
                app.Activate(NSApplicationActivationOptions.ActivateIgnoringOtherWindows);
            }

            return(app.ProcessIdentifier);
        }
Example #2
0
        internal static NSRunningApplication OpenApplicationInternal(ApplicationStartInfo application)
        {
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            if (string.IsNullOrEmpty(application.Application) || !System.IO.Directory.Exists(application.Application))
            {
                throw new ArgumentException("Application is not valid", nameof(application));
            }

            NSUrl appUrl = NSUrl.FromFilename(application.Application);

            var config = new NSMutableDictionary();

            if (application.Args != null && application.Args.Length > 0)
            {
                config.Add(NSWorkspace.LaunchConfigurationArguments, NSArray.FromStrings(application.Args));
            }

            if (application.Environment != null && application.Environment.Count > 0)
            {
                var envValueStrings = application.Environment.Values.Select(t => new NSString(t)).ToArray();
                var envKeyStrings   = application.Environment.Keys.Select(t => new NSString(t)).ToArray();

                config.Add(NSWorkspace.LaunchConfigurationEnvironment, NSDictionary.FromObjectsAndKeys(envValueStrings, envKeyStrings));
            }

            NSWorkspaceLaunchOptions options = 0;

            if (application.Async)
            {
                options |= NSWorkspaceLaunchOptions.Async;
            }
            if (application.NewInstance)
            {
                options |= NSWorkspaceLaunchOptions.NewInstance;
            }
            if (application.HideFromRecentApps)
            {
                options |= NSWorkspaceLaunchOptions.WithoutAddingToRecents;
            }

            var app = NSWorkspace.SharedWorkspace.LaunchApplication(appUrl, options, config, out NSError error);

            if (app == null)
            {
                LoggingService.LogError(error.LocalizedDescription);
            }

            return(app);
        }
Example #3
0
 public virtual NSRunningApplication LaunchApplication(NSUrl url, NSWorkspaceLaunchOptions options, NSDictionary configuration, NSError error)
 {
     return(LaunchApplication(url, options, configuration, out error));
 }
Example #4
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor)
 {
     return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null));
 }
Example #5
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor, string[] identifiers)
 {
     // Ignore the passed in argument, because if you pass it in we will crash on cleanup.
     return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null));
 }
Example #6
0
 public virtual NSRunningApplication LaunchApplication(NSUrl url, NSWorkspaceLaunchOptions options, NSDictionary configuration, NSError error)
 {
     return LaunchApplication (url, options, configuration, out error);
 }
Example #7
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor)
 {
     return _OpenUrls (urls, bundleIdentifier, options, descriptor, null);
 }
Example #8
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor, string[] identifiers)
 {
     // Ignore the passed in argument, because if you pass it in we will crash on cleanup.
     return _OpenUrls (urls, bundleIdentifier, options, descriptor, null);
 }