Skip navigation

"set time of" changes more than targeted variable

341 Views 4 Replies Latest reply: Feb 7, 2013 7:46 AM by Pierre L. RSS
djimmer Calculating status...
Currently Being Moderated
Feb 7, 2013 4:13 AM

Dear Applescripters,

 

I am currently writing a script that creates iCal events from entries made in an Excel sheet. The scripts tells Excel to return a list of dates and times which should be the basis for a series of new events in iCal.

 

Somewhere in the script I am defining a start and an end-date from the list I got from the Excel sheet in two separate variables. However, when I try to set the time of the last variable (it doesn't matter which is last), the time of the first variable is changed as well.

 

 

Below I've copy and pasted an example with two variables that contain the content I would get from the Excel file.  The problem occurs when I try to change the time of 'startTime' and 'endTime' with "set time". As soon as I change the time of 'endTime', the time of 'startTime' is changed to the same value. This only seems to occur when I change the time property using values obtained from the lists I get from the Excel file.

 

 

I must have done something wrong but I cannot figure it out, so if anybody can help me, that would be great!

 

Thanks in advance.

 

 

set targetDateList to {{date "Sunday, February 3, 2013 12:00:00 AM"}, {date "Friday, February 15, 2013 12:00:00 AM"}, {date "Friday, February 15, 2013 12:00:00 AM"}, {date "Tuesday, February 19, 2013 12:00:00 AM"}, {date "Monday, February 25, 2013 12:00:00 AM"}, {date "Monday, February 25, 2013 12:00:00 AM"}, {date "Monday, March 4, 2013 12:00:00 AM"}, {date "Monday, March 4, 2013 12:00:00 AM"}, {""}, {date "Tuesday, March 5, 2013 12:00:00 AM"}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}}

 

set targetTime to {{"13.00-15.00"}, {"9.15-10.45"}, {"11.45-13.15"}, {"10.45-12.15"}, {"12.45-14.15"}, {"14.45-16.15"}, {"10.15-11.45"}, {"12.45-14.15"}, {""}, {"13.45-15.15"}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}}

 

set oldDelimiters to {""}

set AppleScript's text item delimiters to {"-", "."}

 

set startEndTime to (item 1 of (item 1 of targetTime))

set startTime to item 1 of (item 1 of targetDateList)

set endTime to item 1 of (item 1 of targetDateList)



set time of startTime to hours * (text item 1 of startEndTime) + minutes * (text item 2 of startEndTime)  --This changes startTime to 13:00

set time of endTime to hours * (text item 3 of startEndTime) + minutes * (text item 4 of startEndTime) --This changes endTime to 15:00, but also startTime

 

set AppleScript's text item delimiters to oldDelimiters

 

 

 

 



Macbook Pro 2009, Mac OS X (10.6.2), 13.3", 2.26Ghz, 4Gb Ram

Actions

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.