I use a Palm Treo 650 (and Pimlico’s DateBook 6 calendar software) to sync with iCal. I’ve got a script (thanks to some very nice folks here…kai, craig smith, nigel garvey to mention a few) that pulls events from a given calendar and writes them to a text file (for posting on a web page).
The problem I have is that the DateBook 6 software adds the following to the beginning of every description (or Notes) field:
##@@E@@@@@@@@@@@@@@
I’d like to get rid of this text before I write all the events to the text file.
I’ve never had to trim text like this, so I’m a little lost here.
Anyone have an idea on how to do this?
Best,
reidjazz
Model: G5 dual 2 gig (late 2004)
Browser: Firefox 2.0.0.11
Operating System: Mac OS X (10.4)
if there in no @-character in the rest of the text, you can use
set txt to "##@@E@@@@@@@@@@@@@@Howdy"
set {TID, text item delimiters} to {text item delimiters, "@"}
set txt to last text item of txt
set text item delimiters to TID
txt --> "Howdy"
Stefan,
Thanks for your suggestion…unfortunately, I can’t guarantee that there won’t be a ‘@’ symbol somewhere later in the text.
Seems like there would be someway to do this based on the number of characters (or even setting the ##@@E@@@@@@@@@@@@@@ string to a variable and choosing all text in the description property EXCEPT ##@@E@@@@@@@@@@@@@@).
is the string ##@@E@@@@@@@@@@@@@@ always exactly the same?
Then you can use
set txt to "##@@E@@@@@@@@@@@@@@Howdy"
set {TID, text item delimiters} to {text item delimiters, "##@@E@@@@@@@@@@@@@@"}
set txt to last text item of txt
set text item delimiters to TID
txt --> "Howdy"
Stefan,
Unfortunately, this results in the error below:
iCal got an error: Can’t make text item delimiters into type reference.
Below is my entire script, just so you can get a look at the context:
set theYear to text returned of (display dialog "Please enter a year:" default answer (current date)'s year)
tell (choose from list {"January", "February", "March", "April", "May", "June", "July", "August", ¬
"September", "October", "November", "December"} with prompt "Please choose a month:")
if it is false then error number -128
set theMonth to item 1
end tell
tell application "TextWrangler"
activate
if not (exists document "NewGigs") then
make new document at beginning with properties {name:"NewGigs"}
end if
end tell
set {preDate, postDate} to monthRange(theMonth, theYear)
tell application "iCal"
set myEvents to properties of events of calendar "Gigs" whose start date > preDate and start date < postDate
my sortEvents(myEvents, 1, count myEvents)
repeat with i in myEvents
set gigName to summary of i
set beginTime to formatDate(start date of i) of me
set endTime to formatDate(end date of i) of me
set gigNotes to (description of i)
set {TID, text item delimiters} to {text item delimiters, "##@@E@@@@@@@@@@@@@@"}
set gigNotes to last text item of gigNotes
set text item delimiters to TID
tell application "TextWrangler"
activate
set last line of document "NewGigs" to beginTime & "," & endTime & "," & gigName & "," & gigName & "," & gigNotes & "," & "general" & return
end tell
end repeat
tell application "TextWrangler" to activate
end tell
on sortEvents(a, l, r)
script o
property p : a
end script
using terms from application "iCal"
repeat with i from l + 1 to r
set thisEvent to o's p's item i
set thisTime to thisEvent's start date
repeat with j from i to l by -1
if (j > l) and (thisTime comes before o's p's item (j - 1)'s start date) then
set o's p's item j to o's p's item (j - 1)
else
set o's p's item j to thisEvent
exit repeat
end if
end repeat
end repeat
end using terms from
end sortEvents
on monthRange(m, y)
tell {(date (m & " 1 " & y)) - 1}
set end to beginning + 32 * days + 1
set end's day to 1
it
end tell
end monthRange
on formatDate(someDate)
tell (someDate as «class isot» as string) to return text 1 thru 10 & " - " & text 12 thru 16
end formatDate
set txt to "##@@E@@@@@@@@@@@@@@Howdy"
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "##@@E@@@@@@@@@@@@@@"}
set txt to last text item of txt
set AppleScript's text item delimiters to ASTID
txt --> "Howdy"
if the description is empty, then it could be missing value
Try this
.
set gigNotes to (description of i)
if gigNotes is not missing value then
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "##@@E@@@@@@@@@@@@@@"}
set gigNotes to last text item of gigNotes
set text item delimiters to ASTID
else
set gigNotes to ""
end if
.
It seems that the code you gave me puts in an extra “¬” after it’s done…this will mess up my csv file that I upload to my CMS web program. How can I delete this extra “¬”?
my code doesn’t create this character, it must be in the string,
maybe you could filter it with
.
set gigNotes to (description of i)
if gigNotes is not missing value then
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "##@@E@@@@@@@@@@@@@@"}
set gigNotes to last text item of gigNotes
set AppleScript's text item delimiters to ASTID
if gigNotes ends with "¬" then set gigNotes to text 1 thru -2 of gigNotes
else
set gigNotes to ""
end if
.