Auto "Show Save File" Menu Item Script

I can NEVER freakin find these persistent data path files on my Mac, so after some googling, I found a public domain script that opens files or folders from the unity editor, created a menu item out of it, and tailored it to be an “RPG Save System” editor menu at the top… hope you like it…

this will work on both Mac and Windows…

Name this script ShowSaveFile

using UnityEditor;
using UnityEngine;
using System.IO;

public class ShowSaveFile : MonoBehaviour
{
	public static bool IsInMacOS
    {
        get
        {
            return UnityEngine.SystemInfo.operatingSystem.IndexOf("Mac OS") != -1;
        }
    }

    public static bool IsInWinOS
    {
        get
        {
            return UnityEngine.SystemInfo.operatingSystem.IndexOf("Windows") != -1;
        }
    }

    [MenuItem("RPG Save System/Show Save file(s)")]
	public static void Test()
	{
		Open(Application.persistentDataPath);
	}

	public static void OpenInMac(string path)
	{
		bool openInsidesOfFolder = false;

		// try mac
		string macPath = path.Replace("\\", "/"); // mac finder doesn't like backward slashes

		if (System.IO.Directory.Exists(macPath)) // if path requested is a folder, automatically open insides of that folder
		{
			openInsidesOfFolder = true;
		}

		if (!macPath.StartsWith("\""))
		{
			macPath = "\"" + macPath;
		}

		if (!macPath.EndsWith("\""))
		{
			macPath = macPath + "\"";
		}

		string arguments = (openInsidesOfFolder ? "" : "-R ") + macPath;

		try
		{
			System.Diagnostics.Process.Start("open", arguments);
		}
		catch (System.ComponentModel.Win32Exception e)
		{
			// tried to open mac finder in windows
			// just silently skip error
			// we currently have no platform define for the current OS we are in, so we resort to this
			e.HelpLink = ""; // do anything with this variable to silence warning about not using it
		}
	}

	public static void OpenInWin(string path)
	{
		bool openInsidesOfFolder = false;

		// try windows
		string winPath = path.Replace("/", "\\"); // windows explorer doesn't like forward slashes

		if (System.IO.Directory.Exists(winPath)) // if path requested is a folder, automatically open insides of that folder
		{
			openInsidesOfFolder = true;
		}

		try
		{
			System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder ? "/root," : "/select,") + winPath);
		}
		catch (System.ComponentModel.Win32Exception e)
		{
			// tried to open win explorer in mac
			// just silently skip error
			// we currently have no platform define for the current OS we are in, so we resort to this
			e.HelpLink = ""; // do anything with this variable to silence warning about not using it
		}
	}

	public static void Open(string path)
	{
		if (IsInWinOS)
		{
			OpenInWin(path);
		}
		else if (IsInMacOS)
		{
			OpenInMac(path);
		}
		else // couldn't determine OS
		{
			OpenInWin(path);
			OpenInMac(path);
		}
	}
}
7 Likes

OMG thanks! This is super helpful!

2 Likes

This is very handy. I would like to make one important note: This script should be in a folder named Editor. (It can be under Scripts/Saving/Editor, for example.) If it not in an editor folder, you will not be able to Build the game. This goes for any code that uses UnityEditor.

1 Like

I had no idea… will add that to the original post… thanks!!

THANK YOU! x10000000!!!

1 Like

We got a god among men right here thank you very much.

Hi everyone, maybe it is like a 2 years reply but I cannot find the DATA ARCHIVE to be deleted. I’m on MAC, I’ve searched on internet and they way it is on application support folder but I cannot find it within application support folder. I’ve created the script that HeathClose posted…but I don’t know what to do with it. Can anyone help me? Thank you in advance :smiley: !

I’ve just found it, I was right clicking on the Asset folder in Unity instead of looking up where the options tab is (FILE,EDIT,ASSETS,GameObject,Component…). It is awesome, thank you HeathClose, and of course gamedev for the tutorial. Have an excellent day!

Nice!
I can confirm it even works on Linux (well, it would treat it as “unknown”, try both ways, and it should be the Mac way that’s working…)

Privacy & Terms