applescript检查今天是否事件

发布于 2025-02-09 23:56:00 字数 189 浏览 2 评论 0原文

有没有办法编码检查iCal的苹果订阅? 我想制作一个applescript:如果今天的事件是,然后执行任务。

或反向:如果事件是今天今天,那么执行任务。

谢谢 ;-)

Is there a way to code an AppleScript that check iCal ?
I want to make an AppleScript that do: if an event is today then do a task.

Or the inverse : if an event is not today then do a task.

Thanks ;-)

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

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

发布评论

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

评论(2

情深缘浅 2025-02-16 23:56:00

要检查日期是否在特定日期内,您必须减去time从日期(和当前日期)开始,该部分实际上将时间设置为0:00:00

该处理程序将其处理日历事件并返回true如果事件的开始日期今天在今天的开始

on isEventInToday(theEvent)
    tell application "Calendar"
        tell (current date) to set startOfToday to it - (its time)
        tell (get start date of theEvent) to set startOfEvent to it - (its time)
        return startOfToday is equal to startOfEvent
    end tell
end isEventInToday

日期作为第二个参数。

一个替代方案是AppleScriptObjc,它可以访问基础框架

use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

on isEventInToday(theEvent)
    tell application "Calendar" to set startDate to start date of theEvent
    set currentCalendar to current application's NSCalendar's currentCalendar()
    return (currentCalendar's isDateInToday:startDate) as boolean
end isEventInToday

To check if a date is within a specific day you have to subtract the time portion from the date (and the current date) which practically sets the time to 0:00:00

This handler takes a Calendar event and returns true if the start date of the event is in today

on isEventInToday(theEvent)
    tell application "Calendar"
        tell (current date) to set startOfToday to it - (its time)
        tell (get start date of theEvent) to set startOfEvent to it - (its time)
        return startOfToday is equal to startOfEvent
    end tell
end isEventInToday

If this handler is called many times create startOfToday outside of the handler and pass it as second parameter.

An alternative is AppleScriptObjC which has access to the Foundation framework

use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

on isEventInToday(theEvent)
    tell application "Calendar" to set startDate to start date of theEvent
    set currentCalendar to current application's NSCalendar's currentCalendar()
    return (currentCalendar's isDateInToday:startDate) as boolean
end isEventInToday
扶醉桌前 2025-02-16 23:56:00

日历。APP检查事件应在事件的指示开始时间时执行附加警报。您有能力在事件开始时间之前的某个时间来指示日历。提供的警报之一是打开文件警报,这是您所需要的。

因此,

  1. 创建新事件,右键单击,然后单击“获取信息”
  2. 设置事件的开始时间(字段“ start:”信息的开始时间)。例如,在当前时间10分钟后。
  3. 单击“警报:“信息”字段
  4. 在“事件时”中的“弹出菜单”中选择“(例如)
  5. 单击“自定义...”弹出菜单的字段
  6. 选择“打开文件”,而不是其他警报类型
  7. 选择“其他”。 ..“而不是“日历” - >打开选择文件对话框
  8. 选择要在文件系统中打开的脚本(或应用程序)。
  9. 单击“现在应用”

,在事件的指示开始时间上,它将在默认脚本编辑器中自动打开您的附件编译脚本,或者将运行 script作为应用程序,附着。或者,它将打开 preview.app中的一些图像,如果附加了图像文件,请打开。即使galendar.app根本不运行。

在YouTube上存在此视频教程以帮助更多帮助: https://www.youtube.com/wwatch.com/wwatch ?v = 2hhfzichegy 对于使用Mac 上的自定义日历警报。

The Calendar.app checks itself when the event should perform attached alerts at the indicated start time of event. You have ability to indicate to Calendar.app to perform attached alert some time before start time of event, as well. One of provided alerts is open file alert, which is what you need in your case.

So,

  1. create new event, right click, then click Get Info
  2. set the start time of event (field "starts:" of info). For example, 10 minutes after the current time.
  3. Click "alert:" field of info
  4. Select in the pop up menu "At time of event" (for example)
  5. Click "Custom..." field of pop up menu
  6. Choose "Open file" instead of other alert type
  7. Select "Other..." instead of "Calendar" --> opens choose file dialog
  8. Select the script (or app) you want to be opened in your file system.
  9. Click "Apply"

Now, on indicated start time of the event, it will automatically open your attached compiled script in default script editor, or will run script saved as application if one was attached. Or, it will open some image in the Preview.app if the image file was attached, an so on. Even if the Calendar.app is not running at all.

On the Youtube exists this video tutorial to help more: https://www.youtube.com/watch?v=2HhFzIcHEGY for Using Custom Calendar Alerts On Your Mac.

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