如何重复或循环一个applescript [英] how to repeat or loop an applescript

查看:48
本文介绍了如何重复或循环一个applescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个选项来为苹果邮件中的所有未读邮件着色,我找到了以下脚本

I was looking for an option to color all unread mails in apple mail and I found the following script

tell application "Mail"

set background color of (messages of inbox whose read status is false) to red --unread
set background color of (messages of inbox whose read status is true) to none --default read

end tell

我将此脚本添加到邮件规则中,该规则适用于每封邮件,然后它几乎完美运行.唯一的问题是它只能工作一次.所以如果我收到一条新消息,脚本不会注意到它(所以它不是红色的,只有粗体),或者如果我阅读了一封电子邮件,那么它仍然是红色的.请有人帮助我,该脚本将循环运行,或者该脚本将每秒运行一次.

I added this script to a mail rule, which applies to every message, then it works almost perfect. The only problem is that it works only for one time. So if I get a new message, than the script doesn't notice it (so it is not red, only bold), or if I read an email, then it will be still red. Please can someone help me, that the script will run in loop, or that the script will run each second.

仅供参考,我是 Windows 用户(mac 对我来说真的很新),我正在寻找计划任务选项,但我没有在我的 mac 上找到这么简单的东西.

Just for information, I´m an windows user (mac is really new for me) and I was looking for an scheduled task option, but I didn't found such easy thing on my mac.

推荐答案

您有多种运行计划任务的选项.Apple 建议使用launchd"代理.只需谷歌启动教程"即可获得许多示例.

You have several options to run scheduled tasks. Apple suggests to use the "launchd" agent. Just google "launchd tutorial" for many examples.

基本原理是这样的……你用你想要的任何指令创建一个 plist 文件(一个带有 .plist 文件扩展名的 xml 文本文件),然后把它放在文件夹 ~/Library/LaunchAgents 中.这些教程将向您展示如何创建许多不同类型的 plist 文件.将 plist 添加到该文件夹​​后,请注销/登录以使其生效.要禁用 plist fie 运行,然后将其从文件夹中删除并注销/登录.就这么简单.

The basics are this... you create a plist file (an xml text file with the .plist file extension) with whatever instructions you want and put that it in the folder ~/Library/LaunchAgents. The tutorials will show you how to create many different kinds of plist files. Once you add your plist to that folder then logout/login to make it take effect. To disable a plist fie from running then remove it from the folder and logout/login. It's that simple.

作为您特定请求的示例 plist,此示例将每 60 秒运行一次您的 applescript...

As an example plist for your specific request, this one will run your applescript every 60 seconds...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.myName.myProgramName</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>/path/to/applescript.scpt</string>
    </array>
    <key>StartInterval</key>
    <integer>60</integer>
</dict>
</plist>

因此,在那个 plist 示例中,您只需将值放在com.myName.myProgramName"、/path/to/applescript.scpt"和60"中,即运行 applescript 的秒数.

So in that plist example you just need to put your values in "com.myName.myProgramName", "/path/to/applescript.scpt", and "60" which is the number of seconds to run the applescript.

注意:您应该将 plist 文件命名为与com.myName.myProgramName"相同的名称,并将.plist"作为其文件扩展名.

NOTE: you should name your plist file the same name as you give for "com.myName.myProgramName" with ".plist" as its file extension.

祝你好运.

这篇关于如何重复或循环一个applescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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