Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created August 22, 2014 08:42
Show Gist options
  • Save anchan828/4af242328bbdfbfd6c41 to your computer and use it in GitHub Desktop.
Save anchan828/4af242328bbdfbfd6c41 to your computer and use it in GitHub Desktop.
エディタ再生時にiTunesを一時停止&エディタ再生をやめた時にiTunesを再生する
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
[InitializeOnLoad]
public class iTunes
{
static iTunes ()
{
EditorApplication.playmodeStateChanged += () => {
if (EditorApplication.isPlayingOrWillChangePlaymode)
Pause ();
else
Play ();
};
}
static void Play ()
{
Execute (CreateScpt ("play"));
}
static void Pause ()
{
Execute (CreateScpt ("pause"));
}
static void Execute (string path)
{
System.Diagnostics.Process.Start ("osascript", path);
}
static string CreateScpt (string cmd)
{
var scptPath = "Temp/" + cmd + ".scpt";
var sb = new StringBuilder ();
if (!File.Exists (scptPath)) {
sb.AppendLine ("tell application \"iTunes\"");
sb.Append ("\t").AppendLine (cmd);
sb.Append ("end tell");
File.WriteAllText (scptPath, sb.ToString ());
}
return scptPath;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment