- Home /
How can I start a process to open Finder to point to a file?
I'm working on a standalone for OSX and Windows that will output some data to a text file, and I'd like for Unity to open the native file browser to point to that file when it's finished (so users can email me the file, etc.). So far I have the following:
void OnDataParsed (string path)
{
#if UNITY_STANDALONE_OSX || UNITY_EDITOR
try
{
Process process = new Process ();
process.StartInfo.FileName = "open";
process.StartInfo.Arguments = "-n -R " + path.Replace (" ", "\\ ");
UnityEngine.Debug.Log (process.StartInfo.FileName);
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.ErrorDataReceived += OnFinderError;
if (process.Start ())
{
UnityEngine.Debug.Log ("Started properly");
process.BeginErrorReadLine ();
process.BeginOutputReadLine ();
}
else
{
UnityEngine.Debug.Log ("Error");
}
}
catch (System.Exception e)
{
UnityEngine.Debug.Log (e.Message);
}
#endif
}
void OnFinderError (object sender, DataReceivedEventArgs args)
{
UnityEngine.Debug.Log (args.Data);
}
Which, on running in the editor, prints "Started properly" but no finder window shows up. I see the same result regardless of whether "UseShellExecute" is true or false (I set it to false before I copy/pasted to redirect output). Any ideas on what I might be doing wrong?
Comment