AppleScript Application

Discussion in 'Mac Programming' started by MacGeekJunior, Sep 2, 2012.

  1. MacGeekJunior macrumors newbie

    Joined:
    Mar 13, 2011
    #1
    Hi All,
    I have hardly any idea on how to make an applescript app. It is a fairly simple app that will allow me to turn read receipts on and off.
    This is what I want my application to do:
    A Dialog pops up and asks if you want to turn Read Receipts on or off with with two buttons (on and off).
    If 'on' is pressed: terminal is opened and then this is typed in:
    defaults write com.apple.mail UserHeaders '{"Disposition-Notification-To" = "Name <email@address>"; }'
    If 'off' is pressed: terminal is opened and then this is typed in:
    defaults delete com.apple.mail UserHeaders
    Then terminal is closed.

    End of application.

    This is all the code I have so far:
    tell application "Terminal"
    activate
    end tell

    Thanks guys for the help.
     
  2. Red Menace macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    You don't need to use the Terminal, a shell script can be run directly from the AppleScript, for example:

    Code:
    property emailAddress : quote & "Name <email@address>" & quote
    
    display alert "-- Set Mail Read Receipts --" message "This script will set a preference for Read Receipts in the Mail application (com.apple.mail UserHeaders)." buttons {"Cancel", "On", "Off"} cancel button "Cancel" default button "Cancel"
    
    if button returned of the result is "On" then
    	do shell script "defaults write com.apple.mail UserHeaders '{\"Disposition-Notification-To\" = " & emailAddress & "; }'"
    else
    	do shell script "defaults delete com.apple.mail UserHeaders"
    end if
     
  3. MacGeekJunior thread starter macrumors newbie

    Joined:
    Mar 13, 2011
    #3
    Thanks

    Thanks. Works perfectly.
     

Share This Page