Source code: macos/MacOSActions.java
1 /*
2 * :tabSize=8:indentSize=8:noTabs=false:
3 * :folding=explicit:collapseFolds=1:
4 *
5 * MacOSActions.java
6 * Copyright (C) 2002 Kris Kopicki
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 package macos;
24
25 //{{{ Imports
26 import java.io.*;
27 import javax.swing.*;
28 import com.apple.cocoa.application.*;
29 import com.apple.cocoa.foundation.*;
30 import org.gjt.sp.jedit.*;
31 //}}}
32
33 public class MacOSActions
34 {
35 //{{{ showInFinder() method
36 public static void showInFinder(String path)
37 {
38 if (new File(path).exists())
39 {
40 //Remember to make this an option later
41 //NSApplication.sharedApplication().hide(jEdit.getPlugin("MacOSPlugin"));
42 NSWorkspace.sharedWorkspace().selectFile(path,path);
43 }
44 } //}}}
45
46 //{{{ runScript() method
47 public static void runScript(String path)
48 {
49 /*File file = new File(path);
50
51 if (file.exists())
52 {
53 try {
54 BufferedReader reader = new BufferedReader(new FileReader(file));
55 StringBuffer code = new StringBuffer();
56 String line;
57
58 while ((line = reader.readLine()) != null)
59 code.append(line);
60
61 NSAppleScript script = new NSAppleScript(code.toString());
62 script.compile(new NSMutableDictionary());
63 script.execute(new NSMutableDictionary());
64
65 /*
66 String[] args = {"osascript",path};
67 Process proc = Runtime.getRuntime().exec(args);
68 BufferedReader r = new BufferedReader(
69 new InputStreamReader(proc.getErrorStream()));
70 //proc.waitFor();
71
72 String mesg = new String();
73 String line;
74 while ((line = r.readLine()) != null)
75 {
76 if (!line.startsWith("##"))
77 mesg += line;
78 }
79 r.close();
80
81 if (proc.exitValue() != 0)
82 JOptionPane.showMessageDialog(null,mesg,
83 "Script Error",JOptionPane.ERROR_MESSAGE);
84 } catch (Exception ex) {}
85 }*/
86 new ScriptRunner(path).start();
87 //SwingUtilities.invokeLater(new ScriptRunner(path));
88 } //}}}
89
90 //{{{ ScriptRunner class
91 static class ScriptRunner extends Thread
92 {
93 private String path;
94
95 public ScriptRunner(String path)
96 {
97 this.path = path;
98 }
99
100 public void run()
101 {
102 File file = new File(path);
103
104 if (file.exists())
105 {
106 try {
107 BufferedReader reader = new BufferedReader(new FileReader(file));
108 StringBuffer code = new StringBuffer();
109 String line;
110
111 while ((line = reader.readLine()) != null)
112 code.append(line);
113
114 NSAppleScript script = new NSAppleScript(code.toString());
115 script.compile(new NSMutableDictionary());
116 script.execute(new NSMutableDictionary());
117 } catch (Exception ex) {}
118 }
119 }
120 } //}}}
121 }