如何获取 _received_ iCal 事件来运行脚本?

发布于 2025-01-08 21:36:19 字数 473 浏览 0 评论 0原文

我正在尝试编写一个 Applescript,该脚本将根据收到来自其他方的邀请安排的时间进行拨出 Skype 通话。

我认为我可以使用 Skype API 的脚本来进行调用,但是我在使用 iCal 时遇到了困难,方法是

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

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

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

一个典型的示例是:

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

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

非常感谢您的任何建议!

I'm trying to write an Applescript that will make an outgoing Skype call at times scheduled by received invites from other parties.

I think I'm fine with the script to Skype's API to make the call, however I'm struggling with iCal with either method of

A) getting the script to run in the background and getting the time of all new events, or

B) getting the event alert to run a one-off script.

The issue with option B) is that although you can set events from within iCal so that the alert runs a script, I need to trigger this from events that have been received.

A typical example would be:

  • All scripts and iCal running on the Host
  • At 10am a User schedules an event (via google cal on portable device) for 3pm** and invites the the Host.
  • At 3pm the script on the Host uses Skype API to make a call to the User.

** this could just as equally be on a date in the future and the requirements still hold.

Many thanks for any advice!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒中人 2025-01-15 21:36:19

由于 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

Since iCal doesn't have any notifications (some applications do like iChat) you'll have to run a "stay open" applescript application. Something like this will do it for your "B" scenario. NOTE: you will have to add the path to your applescript file (the one that makes your Skype call) in the "applescriptPath" variable.

When launched it will get a listing of all the calendar events you have in iCal. It will then run itself every 5 minutes. When it runs it will check the current events against the list of events it originally made. If there are new events then your applescript will be added as an alarm to the new events. This way it keeps track of the current events between runs and only finds the new ones.

So this script should be a good starting point for you. Remember to save it as a stay-open applescript application. You probably will want to modify it. For example I have it checking every calendar for new events but you may have one particular calendar you want to target. Good luck.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文