teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

7

2015/03/04 11:02

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
@@ -11,15 +11,15 @@
11
11
  public class FileChooser : MonoBehaviour
12
12
  {
13
13
  public const string CHOOSE_FILE =
14
- "-e 'POSIX path of (get choose file of application "System Events" activate)'";
14
+ "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
15
15
  public const string CHOOSE_FOLDER =
16
- "-e 'POSIX path of (get choose folder of application "System Events" activate)'";
16
+ "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
17
17
  public const string CHOOSE_NEW_FILE =
18
- "-e 'POSIX path of (get choose file name of application "System Events" activate)'";
18
+ "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
19
19
  public const string SIMPLE_DIALOG =
20
- "-e 'tell application "System Events"nactivatendisplay dialog "clean" buttons {"OK"}nend tell'";
20
+ "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
21
21
  public const string FORCE_ACTIVATE =
22
- "-e 'tell application "System Events" to activate'";
22
+ "-e 'tell application \"System Events\" to activate'";
23
23
 
24
24
  void Start()
25
25
  {

6

hoge

2015/02/25 12:45

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  でしたら、OSX環境なら、こんな感じでしょうか。
4
4
 
5
- ```lang-c#
5
+ ```lang-csharp
6
6
  using UnityEngine;
7
7
  using System.Collections;
8
8
  using System.Diagnostics;
@@ -11,15 +11,15 @@
11
11
  public class FileChooser : MonoBehaviour
12
12
  {
13
13
  public const string CHOOSE_FILE =
14
- "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
14
+ "-e 'POSIX path of (get choose file of application "System Events" activate)'";
15
15
  public const string CHOOSE_FOLDER =
16
- "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
16
+ "-e 'POSIX path of (get choose folder of application "System Events" activate)'";
17
17
  public const string CHOOSE_NEW_FILE =
18
- "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
18
+ "-e 'POSIX path of (get choose file name of application "System Events" activate)'";
19
19
  public const string SIMPLE_DIALOG =
20
- "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
20
+ "-e 'tell application "System Events"nactivatendisplay dialog "clean" buttons {"OK"}nend tell'";
21
21
  public const string FORCE_ACTIVATE =
22
- "-e 'tell application \"System Events\" to activate'";
22
+ "-e 'tell application "System Events" to activate'";
23
23
 
24
24
  void Start()
25
25
  {

5

えすけーぷ?

2015/02/25 12:45

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
File without changes

4

えすけーぷ

2015/02/25 12:44

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
File without changes

3

lang追加

2015/02/25 12:43

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  でしたら、OSX環境なら、こんな感じでしょうか。
4
4
 
5
- ```
5
+ ```lang-c#
6
6
  using UnityEngine;
7
7
  using System.Collections;
8
8
  using System.Diagnostics;

2

FORCE_ACTIVATEを実装

2015/02/25 12:42

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
@@ -10,59 +10,62 @@
10
10
 
11
11
  public class FileChooser : MonoBehaviour
12
12
  {
13
- public const string CHOOSE_FILE =
13
+ public const string CHOOSE_FILE =
14
- "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
14
+ "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
15
- public const string CHOOSE_FOLDER =
15
+ public const string CHOOSE_FOLDER =
16
- "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
16
+ "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
17
- public const string CHOOSE_NEW_FILE =
17
+ public const string CHOOSE_NEW_FILE =
18
- "-e 'POSIX path of (get choose file name of application \"System Events\" activate)''";
18
+ "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
19
- public const string SIMPLE_DIALOG =
19
+ public const string SIMPLE_DIALOG =
20
- "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
20
+ "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
21
+ public const string FORCE_ACTIVATE =
22
+ "-e 'tell application \"System Events\" to activate'";
21
23
 
22
- void Start ()
24
+ void Start()
23
- {
25
+ {
24
- StartCoroutine (FileChooseDialog (CHOOSE_FILE, (string path) => {
26
+ StartCoroutine (FileChooseDialog (CHOOSE_FILE, (string path) => {
25
- UnityEngine.Debug.Log ("this is " + path);
27
+ UnityEngine.Debug.Log ("this is " + path);
26
- }));
28
+ }));
27
- }
29
+ }
28
30
 
29
- /// <summary>
31
+ /// <summary>
30
- /// osascript -e 'tell application "System Events" to POSIX path of (active choose file)'
32
+ /// osascript -e 'tell application "System Events" to POSIX path of (active choose file)'
31
- /// or
33
+ /// or
32
- /// osascript -e 'POSIX path of (get choose file of application "System Events" activate)'
34
+ /// osascript -e 'POSIX path of (get choose file of application "System Events" activate)'
33
- /// </summary>
35
+ /// </summary>
34
- /// <returns>The choose dialog.</returns>
36
+ /// <returns>The choose dialog.</returns>
35
- public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed)
37
+ public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed)
36
- {
38
+ {
37
- Process fileDialog = new Process ();
39
+ Process fileDialog = new Process ();
38
- fileDialog.StartInfo = new ProcessStartInfo ()
40
+ fileDialog.StartInfo = new ProcessStartInfo ()
39
- {
41
+ {
40
- FileName = "osascript",
42
+ FileName = "osascript",
41
- Arguments = chooseType,
43
+ Arguments = chooseType,
42
- CreateNoWindow = true,
44
+ CreateNoWindow = true,
43
- UseShellExecute = false,
45
+ UseShellExecute = false,
44
- RedirectStandardOutput = true,
46
+ RedirectStandardOutput = true,
45
- RedirectStandardError = true,
47
+ RedirectStandardError = true,
46
- };
48
+ };
47
- StringBuilder result = new StringBuilder ();
49
+ StringBuilder result = new StringBuilder ();
48
- fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
50
+ fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
49
- result.Append (e.Data);
51
+ result.Append (e.Data);
50
- };
52
+ };
51
- fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
53
+ fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
52
- UnityEngine.Debug.LogError (e.Data);
54
+ UnityEngine.Debug.LogError (e.Data);
53
- };
55
+ };
54
- fileDialog.Start ();
56
+ fileDialog.Start ();
55
- fileDialog.BeginOutputReadLine ();
57
+ fileDialog.BeginOutputReadLine ();
56
- fileDialog.BeginErrorReadLine ();
58
+ fileDialog.BeginErrorReadLine ();
59
+ yield return null;
60
+ Process.Start (new ProcessStartInfo () { FileName = "osascript", Arguments = FORCE_ACTIVATE });
57
- while (fileDialog.HasExited == false) {
61
+ while (fileDialog.HasExited == false) {
58
- yield return null;
62
+ yield return null;
59
- }
63
+ }
60
- fileDialog.Close ();
64
+ fileDialog.Close ();
61
- fileDialog.Dispose ();
65
+ fileDialog.Dispose ();
62
- onClosed.Invoke (result.ToString ());
66
+ onClosed.Invoke (result.ToString ());
63
- }
67
+ }
64
68
  }
65
-
66
69
  ```
67
70
 
68
71
  osascriptというコマンドがあるので、これを使えば標準機能なら概ね操作できます。

1

コード微修正

2015/02/25 12:38

投稿

satanabe1
satanabe1

スコア113

answer CHANGED
@@ -34,7 +34,8 @@
34
34
  /// <returns>The choose dialog.</returns>
35
35
  public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed)
36
36
  {
37
+ Process fileDialog = new Process ();
37
- ProcessStartInfo psi = new ProcessStartInfo ()
38
+ fileDialog.StartInfo = new ProcessStartInfo ()
38
39
  {
39
40
  FileName = "osascript",
40
41
  Arguments = chooseType,
@@ -43,8 +44,6 @@
43
44
  RedirectStandardOutput = true,
44
45
  RedirectStandardError = true,
45
46
  };
46
- Process fileDialog = new Process ();
47
- fileDialog.StartInfo = psi;
48
47
  StringBuilder result = new StringBuilder ();
49
48
  fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
50
49
  result.Append (e.Data);