derlandson Posted January 18, 2012 Posted January 18, 2012 Hi, I am using FM to generate ical files that contain specific events that are read from a FM database. Have been doing this for about a year or so with excellent results and it has taken maybe 2 to 3 hours to generate the 3000 or so ical files that run the span of an academic year. The new Lion OS disrupted this because it needs a User ID field in the ics file in order for Lion to read it correctly. Without the UID each event gets imported into iCal twice. So the script below (parts were lifted from the internet) makes a UID and everything works fine except it now takes double the amount of time to run the script. Pretty sure I haven't been the most efficient at script writing across the board (I'm a beginner to intermediate at FM) and am looking to speed up this one script, although maybe there are other areas. Any help is appreciated. Ah, the UID has to be in the form... UID:3A7DD759-55A0-4906-8672-55F1FD3DA68B where the letter/number combo is "random" and/or "unique" (probably not, but iCal re-creates the UID once the event is imported) dan Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1="" ] Loop Commit Records/Requests [ No dialog ] Exit Loop If [ Length(dates_EVENTS::UID1)=8 ] #grab the character at random using the Middle() function below Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1& Middle ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] End Loop Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1&"-" ] Loop Commit Records/Requests [ No dialog ] Exit Loop If [ Length(dates_EVENTS::UID1)=13 ] #grab the character at random using the Middle() function below Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1& Middle ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] End Loop Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1&"-" ] Loop Commit Records/Requests [ No dialog ] Exit Loop If [ Length(dates_EVENTS::UID1)=18 ] #grab the character at random using the Middle() function below Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1& Middle ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] End Loop Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1&"-" ] Loop Commit Records/Requests [ No dialog ] Exit Loop If [ Length(dates_EVENTS::UID1)=23 ] #grab the character at random using the Middle() function below Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1& Middle ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] End Loop Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1&"-" ] Loop Commit Records/Requests [ No dialog ] Exit Loop If [ Length(dates_EVENTS::UID1)=36 ] #grab the character at random using the Middle() function below Set Field [ dates_EVENTS::UID1; dates_EVENTS::UID1& Middle ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] End Loop
comment Posted January 18, 2012 Posted January 18, 2012 Ah, the UID has to be in the form... UID:3A7DD759-55A0-4906-8672-55F1FD3DA68B Are you sure about this? The iCalendar standard requires only that the UID be globally unique, and suggests using something like: [email protected] to achieve it.
Fitch Posted January 18, 2012 Posted January 18, 2012 To address just your script optimizing question, I'd guess the biggest culprit is that you commit the record every single time through the loop. You're also having to calculate the length every time around. I'd do this all in variables and only set the field and commit it at the end. I also insert the hyphens at the end for simplicity: Set Variable[ $counter ; "" ] Loop Set Variable[ $counter ; $counter + 1 ] Exit Loop If [ $counter > 32 ] #grab the character at random using the Middle() function below Set Variable[ $random ; Middle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; Random * 62 ; 1 ) ] Set Variable[ $uid ; $uid & $random ] End Loop Set Variable[ $uid ; Left( $uid ; 8 ) & "-" & Middle( $uid ; 9 ; 4 ) & "-" & Middle( $uid ; 13 ; 4 ) & "-" & Middle( $uid ; 17 ; 4 ) & "-" & Right( $uid ; 12 ) ] Set Field [ dates_EVENTS::UID1; $uid ]
comment Posted January 18, 2012 Posted January 18, 2012 You can also calculate several random character at once, without looping, e.g. Let ( [ alpha = "0123456789ABCDEF" ; n = Length ( alpha ) + 1 ] ; Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) & Middle ( alpha ; Random * n ; 1 ) ) 1
derlandson Posted January 19, 2012 Author Posted January 19, 2012 Fantastic! Thanks for the suggestions. The let statement worked perfectly.
Recommended Posts
This topic is 4692 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now