Created
August 22, 2014 08:42
-
-
Save anchan828/4af242328bbdfbfd6c41 to your computer and use it in GitHub Desktop.
エディタ再生時にiTunesを一時停止&エディタ再生をやめた時にiTunesを再生する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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