My program creates a script for a third-party application. How can I immediately open this script in that application? And can this be done without using files? I write in Xamarin, in C #, but any solution on Objective-C is applicable.

    2 answers 2

    The only working version that I found is to write the data to some file and open it programmatically with the desired application. The NSWorkspace ( class reference ) class helps with this:

    NSString *data = @"Some data"; NSString *filename = @"Some filename"; [data writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil]; [[NSWorkspace sharedWorkspace] openFile:filename withApplication:@"Graphviz"]; 

    For C # and Xamarin, the code is:

     using AppKit; using System.IO; ... string data = "Some data"; string filename = "Some filename"; File.WriteAllText (filename, data); NSWorkspace.SharedWorkspace.OpenFile (filename, "Graphviz"); 

    To work without a file, you probably need the application to support AppleScript, which is not.

      NSDistributedNotificationCenter exists to send a message to another application.

      Send message

       NSString *observedObject = @"com.alexanderyolkin.myapp"; NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter]; [center postNotificationName: @"xpcNote" object: observedObject userInfo: dict deliverImmediately: YES]; 

      Play messages

       NSString *observedObject = @"com.alexanderyolkin.myapp"; NSDistributedNotificationCenter *center = [NSDistributedNotificationCenter defaultCenter]; [center addObserver: self selector: @selector(callbackWithNotification:) name: @"xpcNote" object: observedObject]; 

      We transfer everything that is necessary to NSDictionary