0

基本上我的目标是能够在这个 AppleScript 中使用 Python 的开始和结束日期作为参数。

import commands

cmd = """osascript -e 'tell application "Calendar"
    set all_calendars to title of every calendar

    if "SimpleCal" is in all_calendars then
        set primary_calendar to "SimpleCal"
    else
        create calendar with name "SimpleCal"
        set primary_calendar to "SimpleCal"
    end if

    set start_date_mod to date %s
    set end_date_mod to date "Wednesday, August 14, 2013 at 8:10:00 PM"

    tell calendar primary_calendar
        set new_event to make new event at end with properties {description:"Imported with App", summary:"event_type", location:"", start date: start_date_mod, end date:end_date_mod}
        tell new_event
            make new display alarm at end with properties {trigger interval:-5}
        end tell
    end tell

end tell
'""" % ("Wednesday, August 14, 2013 at 8:00:00 PM")
status = commands.getoutput(cmd)
print status
4

1 回答 1

1

使用 strftime 将 python 日期转换为 Applescript 可以强制转换为日期对象的合适字符串:

import datetime

>>> AS_DATE_FORMAT = "%A, %B %d, %Y %I:%M:%S %p"
>>> right_now = datetime.datetime.now()
>>> date_string = right_now.strftime(AS_DATE_FORMAT)
'Wednesday, August 14, 2013 11:01:10 AM'

然后,在您的 AppleScript 部分中,您只需添加日期:

"set start_date_mod to date %s
set end_date_mod to date " + date_string
于 2013-08-14T15:03:51.043 回答