Posted by member 5575 on 2006-07-13 21:50:54
Cut and pasted from my post to the LSML:
I've been messing around with rainlendar, using Rainy's iCal plugin to import my Google calendar data (Calendar Settings->Private Address->ICAL), but was frustrated that there did not seem to be an easy way to assign rainlendar "profiles" to a given type of event. So, I've come up with a simple brute force approach that works. I'll toss it out here, and then hope someone else has a more elegant solution. The actions are initiated by executing the updateCals commandAlias shown below (grabs all profiles), but could just as easily be done by a timer or an xlabel action, etc. The "bangs" look like so (one per profile):
*CommandAlias updatePCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalPersonal$ "$PersonalDir$rainlendar\Personal.ics" "Default"
*CommandAlias updateBCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalBirthday$ "$PersonalDir$rainlendar\Birthday.ics" "Birthday"
*CommandAlias updateHCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalHolidays$ "$PersonalDir$rainlendar\Holidays.ics" "Holiday"
*CommandAlias updateECal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalHistoric$ "$PersonalDir$rainlendar\Historic.ics" "Reminder"
*CommandAlias updateCals !execute [!command updateBcal][!command updateEcal][!command updateHcal][!command updatePcal]
Each bang calls a script with three arguments:
1) The iCal address from a particular google calendar (this should be private - don't make it public unless you want everyone to be able to see that calendar!),
2) The local file in which the calendar should be stored (I use my personal/rainlendar folder to hold these), and
3) The rainlendar "profile" to which all events in a given calendar should be assigned.
Yep, that means you need a separate calendar for each desired profile as things stand now. =( Fortunately Google calendar supports this, and it's easy to move an event from one calendar to another.
You'll also need to configure the Rainlendar plugin to load each of the desired files (Right click->Config->Plugins tab->Select iCalendar plugin->Click "Settings" button).
Events will be assigned to the "Default" profile if you don't modify the calendar data slightly. That's where the script uses the third argument, inserting the specified profile value in a "CATEGORIES:" entry within each calendar event. Rainy's plugin picks up on that, and uses the first category (the iCal format supports more than one) as the profile. If you want to give it a try, here's the script (save as, e.g., getGoogleCalendar.vbs):
'-----
'
' Google Calendar/Rainlendar Synchronization
' (i.e., WGET + some REGEX modifications, done in VBSCript)
'
'
'-----
'--- General options
Option Explicit ' Enable after debugging is finished
On Error Goto 0 ' Turns on internal error checking and performs Err.Clear
'On Error Resume Next ' Turns off internal error checking
'--- Variable and constant declarations
Const TimeOutSec = 10.0
Const timeDelt = 200. ' milliseconds
Dim CalendarURL, iCalFile, FSO, WSHShell, xml, errstr, btnsel, fOutput
Dim Category, iCalData
Dim timePast: timePast = CSng(0.)
'--- Get calendar from specified link (.ics)
CalendarURL = WScript.Arguments(0)
iCalFile = WScript.Arguments(1)
Category = WScript.Arguments(2)
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set xml = CreateObject("microsoft.xmlHttp")
xml.open "GET",CalendarURL,True 'True = Asynchronous mode
xml.send ""
'--- Wait for up to 'TimeOutSec' seconds if we've not gotten the data yet
While XML.ReadyState 4 ' 4 = successful finish
WScript.Sleep timeDelt
timePast = timePast + timeDelt/1000.
If (timePast >= TimeOutSec) Then
errstr = "Exceeded time out period waiting for response from:"&_
vbcrlf&vbcrlf&CalendarURL&vbcrlf&vbcrlf
btnsel = wshshell.popup(errstr,5,"ERROR",64)
WScript.Quit
End If
Wend
'--- Did an error occur? If so, give some diagnostics and quit.
If Err.Number 0 then
errstr = CalendarURL & " " & Err.Description
btnsel = wshshell.popup(errstr,5,"HTTP ERROR",64)
Err.Clear
Else
If (xml.Status 200) Then
errstr = "ERROR: HTTP status was "& xml.statustext &vbCRLF&vbCRLF&apology
btnsel = wshshell.popup(errstr,5,"HTTP STATUS ERROR",64)
Else
'--- Insert specified CATEGORIES: descriptor before END:VEVENT for each entry
iCalData = xml.ResponseText
iCalData = replace(iCalData, "END:VEVENT", _
"CATEGORIES:"&category&vbcrlf&"END:VEVENT")
'--- Output modified iCal data to local file.
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fOutput = FSO.CreateTextFile(iCalFile,true)
fOutput.Write(iCalData )
fOutput.Close
Set fOutput = Nothing
Set FSO = Nothing
End If
End If
Set xml = Nothing
Set WSHShell = Nothing
Wscript.Quit
I've been messing around with rainlendar, using Rainy's iCal plugin to import my Google calendar data (Calendar Settings->Private Address->ICAL), but was frustrated that there did not seem to be an easy way to assign rainlendar "profiles" to a given type of event. So, I've come up with a simple brute force approach that works. I'll toss it out here, and then hope someone else has a more elegant solution. The actions are initiated by executing the updateCals commandAlias shown below (grabs all profiles), but could just as easily be done by a timer or an xlabel action, etc. The "bangs" look like so (one per profile):
*CommandAlias updatePCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalPersonal$ "$PersonalDir$rainlendar\Personal.ics" "Default"
*CommandAlias updateBCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalBirthday$ "$PersonalDir$rainlendar\Birthday.ics" "Birthday"
*CommandAlias updateHCal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalHolidays$ "$PersonalDir$rainlendar\Holidays.ics" "Holiday"
*CommandAlias updateECal wscript $PersonalDir$rainlendar\getGoogleCalendar.vbs $GoogleCalHistoric$ "$PersonalDir$rainlendar\Historic.ics" "Reminder"
*CommandAlias updateCals !execute [!command updateBcal][!command updateEcal][!command updateHcal][!command updatePcal]
Each bang calls a script with three arguments:
1) The iCal address from a particular google calendar (this should be private - don't make it public unless you want everyone to be able to see that calendar!),
2) The local file in which the calendar should be stored (I use my personal/rainlendar folder to hold these), and
3) The rainlendar "profile" to which all events in a given calendar should be assigned.
Yep, that means you need a separate calendar for each desired profile as things stand now. =( Fortunately Google calendar supports this, and it's easy to move an event from one calendar to another.
You'll also need to configure the Rainlendar plugin to load each of the desired files (Right click->Config->Plugins tab->Select iCalendar plugin->Click "Settings" button).
Events will be assigned to the "Default" profile if you don't modify the calendar data slightly. That's where the script uses the third argument, inserting the specified profile value in a "CATEGORIES:" entry within each calendar event. Rainy's plugin picks up on that, and uses the first category (the iCal format supports more than one) as the profile. If you want to give it a try, here's the script (save as, e.g., getGoogleCalendar.vbs):
'-----
'
' Google Calendar/Rainlendar Synchronization
' (i.e., WGET + some REGEX modifications, done in VBSCript)
'
'
'-----
'--- General options
Option Explicit ' Enable after debugging is finished
On Error Goto 0 ' Turns on internal error checking and performs Err.Clear
'On Error Resume Next ' Turns off internal error checking
'--- Variable and constant declarations
Const TimeOutSec = 10.0
Const timeDelt = 200. ' milliseconds
Dim CalendarURL, iCalFile, FSO, WSHShell, xml, errstr, btnsel, fOutput
Dim Category, iCalData
Dim timePast: timePast = CSng(0.)
'--- Get calendar from specified link (.ics)
CalendarURL = WScript.Arguments(0)
iCalFile = WScript.Arguments(1)
Category = WScript.Arguments(2)
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set xml = CreateObject("microsoft.xmlHttp")
xml.open "GET",CalendarURL,True 'True = Asynchronous mode
xml.send ""
'--- Wait for up to 'TimeOutSec' seconds if we've not gotten the data yet
While XML.ReadyState 4 ' 4 = successful finish
WScript.Sleep timeDelt
timePast = timePast + timeDelt/1000.
If (timePast >= TimeOutSec) Then
errstr = "Exceeded time out period waiting for response from:"&_
vbcrlf&vbcrlf&CalendarURL&vbcrlf&vbcrlf
btnsel = wshshell.popup(errstr,5,"ERROR",64)
WScript.Quit
End If
Wend
'--- Did an error occur? If so, give some diagnostics and quit.
If Err.Number 0 then
errstr = CalendarURL & " " & Err.Description
btnsel = wshshell.popup(errstr,5,"HTTP ERROR",64)
Err.Clear
Else
If (xml.Status 200) Then
errstr = "ERROR: HTTP status was "& xml.statustext &vbCRLF&vbCRLF&apology
btnsel = wshshell.popup(errstr,5,"HTTP STATUS ERROR",64)
Else
'--- Insert specified CATEGORIES: descriptor before END:VEVENT for each entry
iCalData = xml.ResponseText
iCalData = replace(iCalData, "END:VEVENT", _
"CATEGORIES:"&category&vbcrlf&"END:VEVENT")
'--- Output modified iCal data to local file.
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fOutput = FSO.CreateTextFile(iCalFile,true)
fOutput.Write(iCalData )
fOutput.Close
Set fOutput = Nothing
Set FSO = Nothing
End If
End If
Set xml = Nothing
Set WSHShell = Nothing
Wscript.Quit