Reputation: 765
I'm developing an app in Visual Studio which runs on both Windows and MAC (on Mono framework 3.6.0). There are some issues on MAC which can't seem to get solved:
Clipboard.GetText() always returns empty string in Mono on Mac
but I can't use NSPasteboard in Winforms.
http://lists.ximian.com/pipermail/mono-bugs/2010-December/107562.html
Is there any workaround for these issues ?
thanks
Upvotes: 1
Views: 1757
Reputation: 765
Just in case someone else might need it, the solution was to implement copy/paste with pbcopy/pbpaste. Here is a helper class which can be used to copy/paste on OSX:
public class MacClipboard
{
/// <summary>
/// Copy on MAC OS X using pbcopy commandline
/// </summary>
/// <param name="textToCopy"></param>
public static void Copy(string textToCopy)
{
try
{
using (var p = new Process())
{
p.StartInfo = new ProcessStartInfo("pbcopy", "-pboard general -Prefer txt");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardInput = true;
p.Start();
p.StandardInput.Write(textToCopy);
p.StandardInput.Close();
p.WaitForExit();
}
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
}
}
/// <summary>
/// Paste on MAC OS X using pbpaste commandline
/// </summary>
/// <returns></returns>
public static string Paste()
{
try
{
string pasteText;
using (var p = new Process())
{
p.StartInfo = new ProcessStartInfo("pbpaste", "-pboard general");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
pasteText = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
return pasteText;
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
return null;
}
}
}
There is no need for extra installations on MAC as with xsel.
Upvotes: 3