【问题标题】:How do I get a _received_ iCal event to run a script?如何获得 _received_ iCal 事件来运行脚本?
【发布时间】:2012-02-23 22:57:17
【问题描述】:

我正在尝试编写一个 Applescript,它会在收到来自其他方的邀请安排的时间拨打 Skype 电话。

我认为我可以使用 Skype 的 API 的脚本进行调用,但是我在 iCal 的任何一种方法中都遇到了困难

A) 让脚本在后台运行并获取所有新事件的时间,或者

B) 获取事件警报以运行一次性脚本。

选项 B) 的问题在于,虽然您可以在 iCal 中设置事件以便警报运行脚本,但我需要从已收到的事件中触发它。

一个典型的例子是:

  • 在主机上运行的所有脚本和 iCal
  • 上午 10 点,用户安排了下午 3 点的活动(通过便携式设备上的 google cal)** 并邀请主持人。
  • 下午 3 点,主机上的脚本使用 Skype API 呼叫用户。

** 这同样可能是在未来的某个日期,并且要求仍然有效。

非常感谢您的建议!

【问题讨论】:

    标签: applescript skype icalendar


    【解决方案1】:

    由于 iCal 没有任何通知(某些应用程序确实像 iChat),因此您必须运行“保持打开”的 AppleScript 应用程序。像这样的东西会为你的“B”场景做。注意:您必须在“applescriptPath”变量中添加您的 applescript 文件(用于拨打 Skype 电话的文件)的路径。

    启动时,它会列出您在 iCal 中拥有的所有日历事件。然后它将每 5 分钟运行一次。当它运行时,它将根据它最初制作的事件列表检查当前事件。如果有新事件,那么您的 applescript 将作为警报添加到新事件中。这样,它会在运行之间跟踪当前事件,并且只查找新事件。

    所以这个脚本对你来说应该是一个很好的起点。请记住将其保存为保持打开的 applescript 应用程序。您可能会想要修改它。例如,我让它检查每个日历是否有新事件,但您可能有一个要定位的特定日历。祝你好运。

    property storedUIDs : {} -- we use this to check for new events, if an event is not in this list then it is new
    
    global applescriptPath
    
    on run
        set applescriptPath to (path to desktop as text) & "myAlarm.scpt" -- the path to the applescript which is run as the alarm
    end run
    
    on idle
        set newEvents to {}
        tell application "iCal"
            set theCals to calendars
            set allUIDs to {}
            repeat with aCal in theCals
                tell aCal
                    set theseEvents to events
                    repeat with anEvent in theseEvents
                        set thisUID to uid of anEvent
                        set end of allUIDs to thisUID
                        if thisUID is not in storedUIDs then
                            set end of newEvents to contents of anEvent
                        end if
                    end repeat
                end tell
            end repeat
            set storedUIDs to allUIDs
    
            if (count of newEvents) is less than 5 then -- this will prevent the first run of the script from adding the alarm to every event
                repeat with aNewEvent in newEvents
                    -- do something with this new events like add an alarm to run an applescript
                    set theAlarm to make new open file alarm at end of open file alarms of aNewEvent with properties {trigger interval:0, filepath:POSIX path of applescriptPath}
                end repeat
            end if
        end tell
    
        return (5 * 60) -- run every 5 minutes
    end idle
    
    on quit
        set storedUIDs to {}
        continue quit
    end quit
    

    【讨论】:

    • 谢谢(以及延迟回复的道歉 - 没有正确设置我的电子邮件通知!)
    • 附言。我认为 On idle /// end idle 例程在脚本运行后运行是否正确?
    • 是的,丹,“空闲”处理程序是重复运行的处理程序。这就是为什么你让它成为一个保持开放的应用程序......这样它就可以运行了。您会看到,就在结束语句之前,我们“返回 300”,它告诉空闲处理程序每​​ 300 秒运行一次。所以在启动时,“on run”和“on idle”处理程序运行,然后每 300 秒“on idle”处理程序再次运行。当您右键单击停靠图标并退出时,将运行“退出时”处理程序。祝你好运。
    • 非常感谢您的帮助 - 这给了我一个很好的起点和大量的实验。
    • 我已经对其进行了测试(并对其进行了相应的修改以运行 Skype 脚本),它适用于本地创建的 iCal 事件,但是当我使用来自 Google 日历的邀请对其进行测试时,这些事件显示在 iCal 日历中,但似乎没有被 AppleScript 接收?
    猜你喜欢
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    相关资源
    最近更新 更多