Help with CrazyMessageText in Applescript

Discussion in 'Mac Programming' started by alC, Sep 17, 2012.

  1. alC, Sep 17, 2012
    Last edited by a moderator: Sep 17, 2012

    alC macrumors newbie

    Joined:
    Sep 15, 2008
    #1
    Hi All,

    I'm trying to modify the crazymessagetext for my 8 year old niece, so it opens in TextEdit instead of Mail.

    I'm a complete nube on AppleScript and I've tried a heap of things and can't get it to work.

    Can anyone help me?

    Thanks very much for your time,

    Cheers,

    Al

    Here's the original Apple script
    Code:
    (*
    Crazy Message Text
    
    Copyright © 2002–2012 Apple Inc. All rights reserved.
    
    You may incorporate this Apple sample code into your program(s) without
    restriction.  This Apple sample code has been provided "AS IS" and the
    responsibility for its operation is yours.  You are not permitted to
    redistribute this Apple sample code as "Apple sample code" after having
    made changes.  If you're going to redistribute the code, we require
    that you make it clear that the code was descended from Apple sample
    code, but that you've made changes.
    *)
    
    (*
    This script takes a string from the user and then makes a new message
    where each letter has a different font, size, and color.
    *)
    
    property lowFontSize : 36
    property highFontSize : 72
    property messageText : "Happy Birthday!"
    
    repeat
    	set userInput to display dialog "Enter some message text:" & return & return & "Minimum Character Size: " & (lowFontSize as string) & return & "Maximum Character Size: " & (highFontSize as string) default answer messageText buttons {"Cancel", "Set Prefs", "Continue"} default button 3
    	
    	if the button returned of userInput is "Set Prefs" then
    		set minimumFontSize to 9
    		
    		display dialog "Enter the minimum font size to use:" & return & return & ¬
    			"(Must be at least " & (minimumFontSize as string) & ")" default answer lowFontSize buttons {"OK"}
    		set newFontSize to text returned of the result as integer
    		if newFontSize is greater than or equal to minimumFontSize then
    			set lowFontSize to newFontSize
    		else
    			set lowFontSize to minimumFontSize
    		end if
    		
    		display dialog "Enter the maximum font size to use:" & return & return & ¬
    			"(Must be greater than " & (lowFontSize as string) & ")" default answer highFontSize buttons {"OK"}
    		set newFontSize to text returned of the result as integer
    		if newFontSize is greater than lowFontSize then
    			set highFontSize to newFontSize
    		else
    			set highFontSize to lowFontSize
    		end if
    		
    	else -- button returned of userInput is "Continue"
    		set theText to text returned of userInput
    		if theText is not "" then
    			set messageText to theText
    		end if
    		exit repeat
    	end if
    end repeat
    
    set fontList to {"American Typewriter", "American Typewriter Light", "American Typewriter Bold", "American Typewriter Condensed", "American Typewriter Condensed Light", "American Typewriter Condensed Bold", "Arial", "Arial Italic", "Arial Bold", "Arial Bold Italic", "Arial Black", "Baskerville", "Baskerville Italic", "Baskerville SemiBold", "Baskerville Bold", "Baskerville SemiBold Italic", "Baskerville Bold Italic", "Big Caslon Medium", "Comic Sans MS", "Comic Sans MS Bold", "Copperplate", "Copperplate Light", "Copperplate Bold", "Didot", "Didot Italic", "Didot Bold", "Futura Medium", "Futura Medium Italic", "Futura Condensed Medium", "Futura Condensed ExtraBold", "Geneva", "Gill Sans", "Gill Sans Italic", "Gill Sans Light", "Gill Sans Light Italic", "Gill Sans Bold", "Gill Sans Bold Italic", "Herculanum", "Lucida Grande", "Lucida Grande Bold", "Marker Felt Thin", "Marker Felt Wide", "Optima Regular", "Optima Italic", "Optima Bold", "Optima Bold Italic", "Optima ExtraBlack", "Papyrus", "Verdana", "Verdana Italic", "Verdana Bold", "Verdana Bold Italic", "Zapfino"}
    
    tell application "Mail"
    	activate
    	set crazyTextMessage to make new outgoing message with properties {content:messageText, visible:true}
    	
    	tell crazyTextMessage
    		repeat with eachCharacter in characters
    			set font of eachCharacter to (some item of fontList)
    			set size of eachCharacter to (random number from lowFontSize to highFontSize)
    			set color of eachCharacter to {random number from 0 to 65535, random number from 0 to 65535, random number from 0 to 65535}
    		end repeat
    	end tell
    end tell
    
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Change this tell block:

    Code:
    tell application "Mail"
    ...
    ...
    end tell
    with this :

    Code:
    tell application "TextEdit"
    	set crazyTextMessage to make new document with properties {text:messageText}
    	tell crazyTextMessage
    		repeat with eachCharacter in characters
    			set font of eachCharacter to (some item of fontList)
    			set size of eachCharacter to (random number from lowFontSize to highFontSize)
    			set color of eachCharacter to {random number from 0 to 65535, random number from 0 to 65535, random number from 0 to 65535}
    		end repeat
    	end tell
    end tell
     

    Attached Files:

  3. alC thread starter macrumors newbie

    Joined:
    Sep 15, 2008
    #3
    Thankyou Thankyou Thankyou

    Thanks kryten2,

    You're going to make an 8 year old girl in Australia delighted after she gets back from School today.

    Hope you have a fantastic evening in Belgium

    :)

    Al
     
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Thanks. I have a 5 year old niece :D Have a nice day down under.
     
  5. alC thread starter macrumors newbie

    Joined:
    Sep 15, 2008
    #5
    The results of your kindness

    Hi again,

    Just wanted to post a quick pic of what my niece wrote.

    I love the mac community and people like you make a difference

    thanks again :)

    Al

    PS I made it into an app with a pic of her favourite toy snuggles as the icon
     

    Attached Files:

  6. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Love the pic. Looks like snuggles is having a nice sleep as well ;)
     

Share This Page