Easy Applescript Help?

Discussion in 'Mac Programming' started by nboychuk, Mar 30, 2009.

  1. macrumors newbie

    Joined:
    Mar 30, 2009
    Location:
    Guelph, ON
    #1
    So i'm attempting to "write" my first applescript. It has so far consisted of piecing together other random scripts, and endless Googling. What I would like it to do is read the title of an iCal event (football matches), find the opposing team's name, and set a generic picture (to be used somewhere else) as the team's crest. The folder holding the script also has all of the crests, and the generic picture. I used a script to set a picture to the currently playing iTunes artwork as a start, since I figured it'd be kinda similar .. turns out I just confused myself. :confused:

    Code:
    do shell script "ruby -e 'puts File.dirname(\"" & POSIX path of (path to me as string) & "\")'"
    set basePath to (POSIX file (the result) as string) & ":"
    
    set picName to " "
    
    tell application "iCal"
    	tell calendar "Man Utd"
    		set theEvent to first event
    		set theName to summary of theEvent
    		set theDate to start date of theEvent
    	end tell
    end tell
    
    if theName contains "Arsenal" then
    	set picName to "AFC"
    else if theName contains "Aston Villa" then
    	set picName to "AVFC"
    else if theName contains "Everton" then
    	set picName to "EFC"
    else if theName contains "FC Porto" then
    	set picName to "FCP"
    else if theName contains "Hull City" then
    	set picName to "HCAFC"
    else if theName contains "Man City" then
    	set picName to "MCFC"
    else if theName contains "Middlesbrough" then
    	set picName to "MFC"
    else if theName contains "Portsmouth" then
    	set picName to "PFC"
    else if theName contains "Sunderland" then
    	set picName to "SFC"
    else if theName contains "Tottenham" then
    	set picName to "TH"
    else if theName contains "Wigan" then
    	set picName to "WAFC"
    else if theName contains "Chelsea" then
    	set picName to "CFC"
    end if
    
    set realCrest to (basePath & picName & ".tif")
    
    tell application "Finder" to set creator type of realCrest to "????"
    
    tell application "Image Events"
    	set theImage to open realCrest
    	save theImage as TIFF in basePath & "teamCrest.tif" with replacing
    end tell
    
    Also .. i can't quite get it to recognize the correct event. Is there any way to pull the next event in a calendar from iCal?

    Any help on this would be greatly appreciated!
     

Share This Page