回答編集履歴

7

2015/03/04 11:02

投稿

satanabe1
satanabe1

スコア113

test CHANGED
@@ -24,23 +24,23 @@
24
24
 
25
25
  public const string CHOOSE_FILE =
26
26
 
27
- "-e 'POSIX path of (get choose file of application "System Events" activate)'";
27
+ "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
28
28
 
29
29
  public const string CHOOSE_FOLDER =
30
30
 
31
- "-e 'POSIX path of (get choose folder of application "System Events" activate)'";
31
+ "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
32
32
 
33
33
  public const string CHOOSE_NEW_FILE =
34
34
 
35
- "-e 'POSIX path of (get choose file name of application "System Events" activate)'";
35
+ "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
36
36
 
37
37
  public const string SIMPLE_DIALOG =
38
38
 
39
- "-e 'tell application "System Events"nactivatendisplay dialog "clean" buttons {"OK"}nend tell'";
39
+ "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
40
40
 
41
41
  public const string FORCE_ACTIVATE =
42
42
 
43
- "-e 'tell application "System Events" to activate'";
43
+ "-e 'tell application \"System Events\" to activate'";
44
44
 
45
45
 
46
46
 

6

hoge

2015/02/25 12:45

投稿

satanabe1
satanabe1

スコア113

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- ```lang-c#
9
+ ```lang-csharp
10
10
 
11
11
  using UnityEngine;
12
12
 
@@ -24,23 +24,23 @@
24
24
 
25
25
  public const string CHOOSE_FILE =
26
26
 
27
- "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
27
+ "-e 'POSIX path of (get choose file of application "System Events" activate)'";
28
28
 
29
29
  public const string CHOOSE_FOLDER =
30
30
 
31
- "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
31
+ "-e 'POSIX path of (get choose folder of application "System Events" activate)'";
32
32
 
33
33
  public const string CHOOSE_NEW_FILE =
34
34
 
35
- "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
35
+ "-e 'POSIX path of (get choose file name of application "System Events" activate)'";
36
36
 
37
37
  public const string SIMPLE_DIALOG =
38
38
 
39
- "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
39
+ "-e 'tell application "System Events"nactivatendisplay dialog "clean" buttons {"OK"}nend tell'";
40
40
 
41
41
  public const string FORCE_ACTIVATE =
42
42
 
43
- "-e 'tell application \"System Events\" to activate'";
43
+ "-e 'tell application "System Events" to activate'";
44
44
 
45
45
 
46
46
 

5

えすけーぷ?

2015/02/25 12:45

投稿

satanabe1
satanabe1

スコア113

test CHANGED
File without changes

4

えすけーぷ

2015/02/25 12:44

投稿

satanabe1
satanabe1

スコア113

test CHANGED
File without changes

3

lang追加

2015/02/25 12:43

投稿

satanabe1
satanabe1

スコア113

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- ```
9
+ ```lang-c#
10
10
 
11
11
  using UnityEngine;
12
12
 

2

FORCE_ACTIVATEを実装

2015/02/25 12:42

投稿

satanabe1
satanabe1

スコア113

test CHANGED
@@ -22,111 +22,117 @@
22
22
 
23
23
  {
24
24
 
25
- public const string CHOOSE_FILE =
25
+ public const string CHOOSE_FILE =
26
26
 
27
- "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
27
+ "-e 'POSIX path of (get choose file of application \"System Events\" activate)'";
28
28
 
29
- public const string CHOOSE_FOLDER =
29
+ public const string CHOOSE_FOLDER =
30
30
 
31
- "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
31
+ "-e 'POSIX path of (get choose folder of application \"System Events\" activate)'";
32
32
 
33
- public const string CHOOSE_NEW_FILE =
33
+ public const string CHOOSE_NEW_FILE =
34
34
 
35
- "-e 'POSIX path of (get choose file name of application \"System Events\" activate)''";
35
+ "-e 'POSIX path of (get choose file name of application \"System Events\" activate)'";
36
36
 
37
- public const string SIMPLE_DIALOG =
37
+ public const string SIMPLE_DIALOG =
38
38
 
39
- "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
39
+ "-e 'tell application \"System Events\"\nactivate\ndisplay dialog \"clean\" buttons {\"OK\"}\nend tell'";
40
+
41
+ public const string FORCE_ACTIVATE =
42
+
43
+ "-e 'tell application \"System Events\" to activate'";
40
44
 
41
45
 
42
46
 
43
- void Start ()
47
+ void Start()
44
48
 
45
- {
49
+ {
46
50
 
47
- StartCoroutine (FileChooseDialog (CHOOSE_FILE, (string path) => {
51
+ StartCoroutine (FileChooseDialog (CHOOSE_FILE, (string path) => {
48
52
 
49
- UnityEngine.Debug.Log ("this is " + path);
53
+ UnityEngine.Debug.Log ("this is " + path);
50
54
 
51
- }));
55
+ }));
52
56
 
53
- }
57
+ }
54
58
 
55
59
 
56
60
 
57
- /// <summary>
61
+ /// <summary>
58
62
 
59
- /// osascript -e 'tell application "System Events" to POSIX path of (active choose file)'
63
+ /// osascript -e 'tell application "System Events" to POSIX path of (active choose file)'
60
64
 
61
- /// or
65
+ /// or
62
66
 
63
- /// osascript -e 'POSIX path of (get choose file of application "System Events" activate)'
67
+ /// osascript -e 'POSIX path of (get choose file of application "System Events" activate)'
64
68
 
65
- /// </summary>
69
+ /// </summary>
66
70
 
67
- /// <returns>The choose dialog.</returns>
71
+ /// <returns>The choose dialog.</returns>
68
72
 
69
- public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed)
73
+ public IEnumerator FileChooseDialog (string chooseType, System.Action<string> onClosed)
70
74
 
71
- {
75
+ {
72
76
 
73
- Process fileDialog = new Process ();
77
+ Process fileDialog = new Process ();
74
78
 
75
- fileDialog.StartInfo = new ProcessStartInfo ()
79
+ fileDialog.StartInfo = new ProcessStartInfo ()
76
80
 
77
- {
81
+ {
78
82
 
79
- FileName = "osascript",
83
+ FileName = "osascript",
80
84
 
81
- Arguments = chooseType,
85
+ Arguments = chooseType,
82
86
 
83
- CreateNoWindow = true,
87
+ CreateNoWindow = true,
84
88
 
85
- UseShellExecute = false,
89
+ UseShellExecute = false,
86
90
 
87
- RedirectStandardOutput = true,
91
+ RedirectStandardOutput = true,
88
92
 
89
- RedirectStandardError = true,
93
+ RedirectStandardError = true,
90
94
 
91
- };
95
+ };
92
96
 
93
- StringBuilder result = new StringBuilder ();
97
+ StringBuilder result = new StringBuilder ();
94
98
 
95
- fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
99
+ fileDialog.OutputDataReceived += (object sender, DataReceivedEventArgs e) => {
96
100
 
97
- result.Append (e.Data);
101
+ result.Append (e.Data);
98
102
 
99
- };
103
+ };
100
104
 
101
- fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
105
+ fileDialog.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => {
102
106
 
103
- UnityEngine.Debug.LogError (e.Data);
107
+ UnityEngine.Debug.LogError (e.Data);
104
108
 
105
- };
109
+ };
106
110
 
107
- fileDialog.Start ();
111
+ fileDialog.Start ();
108
112
 
109
- fileDialog.BeginOutputReadLine ();
113
+ fileDialog.BeginOutputReadLine ();
110
114
 
111
- fileDialog.BeginErrorReadLine ();
115
+ fileDialog.BeginErrorReadLine ();
112
116
 
113
- while (fileDialog.HasExited == false) {
117
+ yield return null;
114
118
 
115
- yield return null;
119
+ Process.Start (new ProcessStartInfo () { FileName = "osascript", Arguments = FORCE_ACTIVATE });
116
120
 
117
- }
121
+ while (fileDialog.HasExited == false) {
118
122
 
119
- fileDialog.Close ();
123
+ yield return null;
120
124
 
121
- fileDialog.Dispose ();
125
+ }
122
126
 
123
- onClosed.Invoke (result.ToString ());
127
+ fileDialog.Close ();
124
128
 
129
+ fileDialog.Dispose ();
130
+
131
+ onClosed.Invoke (result.ToString ());
132
+
125
- }
133
+ }
126
134
 
127
135
  }
128
-
129
-
130
136
 
131
137
  ```
132
138
 

1

コード微修正

2015/02/25 12:38

投稿

satanabe1
satanabe1

スコア113

test CHANGED
@@ -70,7 +70,9 @@
70
70
 
71
71
  {
72
72
 
73
+ Process fileDialog = new Process ();
74
+
73
- ProcessStartInfo psi = new ProcessStartInfo ()
75
+ fileDialog.StartInfo = new ProcessStartInfo ()
74
76
 
75
77
  {
76
78
 
@@ -87,10 +89,6 @@
87
89
  RedirectStandardError = true,
88
90
 
89
91
  };
90
-
91
- Process fileDialog = new Process ();
92
-
93
- fileDialog.StartInfo = psi;
94
92
 
95
93
  StringBuilder result = new StringBuilder ();
96
94