0

I can use iCal to make a new event.

tell application "iCal"
    tell calendar "Todo"
        set new_event to make new event at end of events
        tell new_event
            set start date to date "Friday, May 6, 2011 4:00:00 PM"
            set end date to date "Friday, May 6, 2011 4:30:00 PM"
            set summary to "Feed ferret"
            set location to "Home 2"
            set allday event to false
            set status to confirmed
        end tell
    end tell
end tell

However, when I use a variable to replace the string, I got an error.

tell application "iCal"
    tell calendar "Todo"
        set new_event to make new event at end of events
        set m_date to "Friday, May 6, 2011 4:00:00 PM" --> variable m_date
        tell new_event
            set start date to date m_date --> Error
            set end date to date "Friday, May 6, 2011 4:30:00 PM"
            set summary to "Feed ferret"
            set location to "Home 2"
            set allday event to false
            set status to confirmed
        end tell
    end tell
end tell

enter image description here

Why can't I use variables for setting up iCal event?

0

1 Answer 1

1

because 'date' is a function that converts the string to a date format that ical accepts so you simply must put 'date' in your variable

on somefunction()
    set m_date to date "Friday, May 6, 2011 4:00:00 PM"
    my make_todo(m_date)
end somefunction

on make_todo(m_date)
    tell application "iCal"
        tell calendar "Todo"
            set new_event to make new event at end of events

            tell new_event
                set start date to m_date
                set end date to date "Friday, May 6, 2011 4:30:00 PM"
                set summary to "Feed ferret"
                set location to "Home 2"
                set allday event to false
                set status to confirmed
            end tell
        end tell
    end tell
end make_todo

ll end tell

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. Actually, I read time info from file and store it into m_date. With date function, is there a way to use a variable as a parameter to data function?
@prosseek that sounds like a separate question but yes
I posted another question for this. Thanks. - stackoverflow.com/questions/5938743/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.