我如何编写 Applescript,它会给我一个每小时弹出警报 [英] How do I write Applescript that will give me an hourly popup alert

查看:29
本文介绍了我如何编写 Applescript,它会给我一个每小时弹出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在我的计算机 (Mac OS X) 上每小时弹出一次警报.我认为用 Applescript 写这个会很简单,但我没有 Applescript 经验.谢谢

I am wondering how to have a popup alert on my computer (Mac OS X) every hour. I figured writing this in Applescript would be pretty simple but I have no Applescript experience. Thanks

推荐答案

在 AppleScript 中用于定期处理事情的基本处理程序是空闲处理程序.

The basic handler for doing things on a regular basis in AppleScript is the idle handler.

on idle
 display dialog "Go back to work" buttons "Work Harder" default button "Work Harder"
 return 3600
end idle

此脚本会在您启动应用程序时弹出一个对话框,然后在按下按钮后每 3,600 秒弹出一个对话框.空闲处理程序返回的任何数字都将是触发下一个空闲事件之前的秒数.

This script will pop up a dialog box when you start the application and then every 3,600 seconds after pressing the button. Whatever number the idle handler returns will be the number of seconds before the next idle event is triggered.

如果您希望它在半小时而不是每 60 分钟一次,您希望空闲脚本返回不同的秒数,可能是 60,然后检查您是否在正确的位置一个小时的一部分.

If you want it to be on the half-hour and not every sixty minutes, you'd want the idle script to return a different number of seconds, perhaps 60, and then check to see if you're at the right part of the hour.

on idle
 if the minutes of the (current date) is 30 then
  display dialog "Go back to work" buttons "Work Harder" default button "Work Harder"
 end if
 return 60
end idle

这只会在半点显示对话框.(与 Unix 一样,AppleScript 的当前日期概念也包括当前时间.)

This will only display the dialog at half past. (Like Unix, AppleScript’s concept of the current date includes the current time.)

在每种情况下,您都希望在 AppleScript 编辑器中保存为应用程序"和保持打开状态",以便让它响应空闲事件而不是在运行后退出.您可以将应用程序添加到帐户"系统首选项中的登录项"列表中,使其在您登录时自动运行.

In each case, you want to save in AppleScript Editor as "Application" and "Stay Open" in order to have it respond to idle events instead of just quitting after running. And you can add the application to your list of "Login Items" in the "Accounts" system preference to make it run automatically when you log in.

这篇关于我如何编写 Applescript,它会给我一个每小时弹出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆