cocoa-applescript

Discussion in 'Mac Programming' started by Airlok apps, Jul 29, 2011.

  1. Airlok apps macrumors newbie

    Joined:
    Jul 25, 2011
    #1
    i'm new to programming and i'm trying to create a cocoa-applescript application with a text view. the idea is that the user writes down there comments and clicks send. this then sends me an email with there comments.
    i think in normal apple script this would be

    set the_dialog to "enter your comments here"
    set email to text returned of (display dialog the_dialog default answer "" buttons {"Cancel", "OK"} default button 2)
    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:false, subject:"My Subject", content:email}
    tell theMessage
    make new to recipient at end of to recipients with properties {name:"example", address:"example@example.co.uk"}
    send theMessage
    end tell
    end tell

    but how do i get this to my text view
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    What have you got so far? Usually you would connect your text view to an outlet in your script, then you can use the various methods such as NSText's string() to get the characters of the text. The rest of the Mail scripting would be the same.
     
  3. Airlok apps thread starter macrumors newbie

    Joined:
    Jul 25, 2011
    #3
    ok, I've looked around and so far i got

    property textView : missing value
    property textField : missing value

    on sendemail_(sender)
    set textFieldValue to textField's stringValue()
    set textViewValue to textView's stringValue()

    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:false, subject:textFieldValue, content:textViewValue}
    tell theMessage
    make new to recipient at end of to recipients with properties {name:"example", address:"example@example.co.uk"}
    send theMessage
    end tell
    end tell
    end sendemail_

    with text view linked to the text view, text field linked to the text field and the send button linked sendemail_ but it still doesn't work!
     
  4. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #4
    First, a few points:

    1) If you open the Debugger Console, an error such as trying to call an incorrect method will be shown so you can get an idea of what you are doing wrong. Note that Xcode deals with errors differently than AppleScript - if there is an error, the particular handler is aborted, so everything past the error winds up being skipped.
    2) A text field is not the same as a text view, so you need to check the particular class (and its parent classes) to see what methods are available.
    3) Some class methods have the same name as an AppleScript reserved word, so when using them you need to surround the name with pipes so that AppleScript interprets it correctly.
    4) The various Cocoa methods return Cocoa objects, so you should coerce them to the desired AppleScript class to make sure they are something that AppleScript can use.

    Try changing the following statements:
    Code:
    		set textFieldValue to textField's stringValue() as text
    		set textViewValue to textView's |string|() as text
    
     

Share This Page