Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript and SubEthaEdit

AppleScript and SubEthaEdit
Thread Tools
Fresh-Faced Recruit
Join Date: Sep 2003
Status: Offline
Reply With Quote
Sep 20, 2003, 04:32 PM
 
Hey, I've got a fairly basic (I hope) AppleScript that I'd like to write.

I need to get the current filename from the active SubEthaEdit window, and then I need to javac that file, while displaying the results... preferrably in a new SubEthaEdit document.


This functionality would be similar to the compile java function in textpad (www.textpad.com)

Ok, so anyone dare to try and help me out here? I really don't know what to do, and I can't get much of any applescript to work, I keep getting errors.. but I think it's because I don't know much AppleScript, and it confuses me...
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Sep 21, 2003, 05:40 AM
 
I knocked something up:

- Annoyingly SubEthaEdit does not seem to allow you to make new documents with text in - or set the text of documents, so I had to use TextEdit for the result.

[edit - tweaked to be slightly nicer.]

Code:
-- Java Compilation Routine on compileMyJava(sourcePath) try set compileResult to (do shell script "javac " & sourcePath) on error someError set compileResult to someError end try return compileResult end compileMyJava tell application "SubEthaEdit" if (number of windows) < 1 then display dialog "There are no open subEthaEdit windows." buttons {"OK"} giving up after 1 -- seconds return -- can't compile nothing! else set frontDoc to text document of front window if modified of frontDoc is true then set saveReply to display dialog "There are Unsaved Changes! Do you want to Save the source? (choosing 'No' will cancel compilation.)" buttons {"No", "Yes"} default button 2 if button returned of saveReply is "No" then return else save frontDoc end if end if try set theSourcePath to path of frontDoc -- display dialog "path: " & theSourcePath on error errorString number errorNumber display dialog "This Document has never been saved to a file- It cannot be Compiled." return end try end if end tell set compileResult to compileMyJava(theSourcePath) if compileResult is equal to "" then say "Source compiled with no errors." -- You can comment out either of these lines. display dialog "No Errors - Your source is now compiled." buttons "OK" default button 1 giving up after 10 -- You can comment out either of these lines. else tell application "TextEdit" activate set resultsDoc to make new document at front set the name of window 1 to "Java Compile results" set the text of resultsDoc to compileResult -- Spit out the compilation error end tell end if
(Last edited by Diggory Laycock; Sep 21, 2003 at 10:05 AM. )
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Sep 21, 2003, 06:13 AM
 
Oh yes - don't forget to put the script into ~/Library/Scripts/Applications/SubEthaEdit/

Then you can call the script from the Script Menu (When you are in SubEthaEdit - it hides it otherwise)

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:11 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2