1 22 23 package macos; 24 25 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 33 public class MacOSActions 34 { 35 public static void showInFinder(String path) 37 { 38 if (new File(path).exists()) 39 { 40 NSWorkspace.sharedWorkspace().selectFile(path,path); 43 } 44 } 46 public static void runScript(String path) 48 { 49 new ScriptRunner(path).start(); 50 } 53 static class ScriptRunner extends Thread 55 { 56 private String path; 57 58 public ScriptRunner(String path) 59 { 60 this.path = path; 61 } 62 63 public void run() 64 { 65 File file = new File(path); 66 67 if (file.exists()) 68 { 69 try { 70 BufferedReader reader = new BufferedReader(new FileReader(file)); 71 StringBuffer code = new StringBuffer (); 72 String line; 73 74 while ((line = reader.readLine()) != null) 75 code.append(line+"\n"); 76 77 NSAppleScript script = new NSAppleScript(code.toString()); 78 NSMutableDictionary compileErrInfo = new NSMutableDictionary(); 79 NSMutableDictionary execErrInfo = new NSMutableDictionary(); 80 if (script.compile(compileErrInfo)) 81 { 82 if (script.execute(execErrInfo) == null) 83 { 84 JOptionPane.showMessageDialog(null, 85 execErrInfo.objectForKey("NSAppleScriptErrorBriefMessage"), 86 jEdit.getProperty("MacOSPlugin.dialog.script.title"), 87 JOptionPane.ERROR_MESSAGE); 88 } 89 } 90 else 91 { 92 JOptionPane.showMessageDialog(null, 93 compileErrInfo.objectForKey("NSAppleScriptErrorBriefMessage"), 94 jEdit.getProperty("MacOSPlugin.dialog.script.title"), 95 JOptionPane.ERROR_MESSAGE); 96 } 97 } catch (Exception ex) {} 98 } 99 } 100 } } 102 | Popular Tags |