I am working on an automator workflow (for 10.4 Tiger) that strips out one line of an iCal event and saves it as a PlainText TextEdit document on the desktop. Ideally I don’t want this text file saved but I am having to do this so it can be merged with more text to create an overdue invoice e-mail.
The automator workflow is pretty straightforward but I am struggling with trying to generate an AppleScript that removes certain characters from the .txt file.
For example, iCal generates a file with the following text:
Summary: Invoice 1/08 is overdue
Through this forum I found a simple script to find and replace words, but it won’t work with the colon and tab after Summary. I want the text "Summary: " to be replaced with nothing “”.
Here is the script I’m trying to use:
tell application "TextEdit" to tell document 1 to set every word where it is "summary: " to ""
set t to "Summary: Invoice 1/08 is overdue"
set {TID, text item delimiters} to {text item delimiters, "Summary:" & tab}
set t to text items of t
set text item delimiters to TID
set t to t as text
--> "Invoice 1/08 is overdue"
PS: TextEdit is not needed, to find and replace plain text
Using the script you provided from Script Editor generates what appears to be a correct result, but when I add the script into the Automator workflow, it doesn’t generate the same result:
From this: “Invoice 1/08 is overdue”
To this: {“Summary: Invoice 1/08 for £637.50 is now overdue”}
Also, I’m only wanting to find and change Summary: (plus the tab) as the text after this will change every single time.
I’ve made some progress and just about circumvented any need for a textedit file.
The automator events are as follows:
Get specified iCal items
links to Invoices Overdue calendar
Event Summary
For Today
Filter Paragraphs
Return paragraphs that contain: is now overdue
View Results
Copy to Clipboard
New Mail Message
To: Subject: and Message: filled in but space left for event summary to be pasted in
Run Applescript
on run {input, parameters}
try
tell application "System Events"
keystroke "v" using command down
end tell
on error errMsg number errNum
set AppleScript's text item delimiters to ASTID
display dialog "Error " & errNum & return & return & errMsg with icon caution buttons {"Cancel"} default button 1
end try
return input
end run
So in essence, anything with the words invoice overdue are copied to the clipboard, from iCal, and a new Mail message opens up with template text already in there and the invoice overdue text is pasted above this template text.
I did find another little script that now removes "Summary: " but I can’t get it to amend either the event summary before or after it’s copied to the clipboard, or when it’s in the new mail message window.
set t to "summary: "
set s to "summary: "
set r to ""
set utid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {s}
set temp_list to text items of t
set AppleScript's text item delimiters to {r}
set t to temp_list as string
set AppleScript's text item delimiters to utid
return t
this Run AppleScript action after the Filter Paragraphs action removes “Summary:” from all found lines
on run {input, parameters}
repeat with i in input
set {TID, text item delimiters} to {text item delimiters, "Summary:" & tab}
set t to text items of i
set text item delimiters to TID
set contents of i to t as text
end repeat
return input
end run
I’m not very familiar with Automator, because I usually do everything directly in AppleScript