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