开发者

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

开发者 https://www.devze.com 2023-03-04 01:13 出处:网络
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

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 mak开发者_Python百科e 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

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号