I’m new to applescript and would like help replaceing selected text in a ical event. I have a calendar “School”. There are a number of events with titles, summary?, such as “MC (SEB)”, “MC (JCD)”, “JCD (MC)” and so on. I would like to write a script that looks for all of the events in “School” and replaces each occurance of “MC” with “My Company”, keeping the rest of the string as is. The end result would be “My Company (SEB)”, “My Company (JCD)”, “JCD (My Compnay)”. Can anyone help with this?
Thanks,
Steve
Model: Mac G4
AppleScript: 1.1
Browser: Safari 412.2
Operating System: Mac OS X (10.4)
Try this:
tell application "iCal"
activate
set ASTID to AppleScript's text item delimiters
get every event of calendar "School"
repeat with thisEvent in result
set newSummary to summary of thisEvent
if newSummary starts with "MC " then
set AppleScript's text item delimiters to "MC "
set newSummary to every text item of newSummary
set AppleScript's text item delimiters to "My Company "
set newSummary to newSummary as text
end if
if newSummary ends with "(MC)" then
set AppleScript's text item delimiters to "(MC)"
set newSummary to every text item of newSummary
set AppleScript's text item delimiters to "(My Company)"
set newSummary to newSummary as text
end if
set summary of thisEvent to newSummary
end repeat
set AppleScript's text item delimiters to ASTID
beep
end tell
Thank you, that did the trick. I was trying to do this using change, but I just couldn’t get it to work.
–Steve