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

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

问题描述

我一直在寻找一个选项,以颜色的所有封未读邮件在Apple Mail中,我发现下面的脚本

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.

只是为了信息,I'm一个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.

推荐答案

您有几个选项来运行计划任务。苹果公司建议使用的launchd代理。只是谷歌的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文本文件),并把它的文件夹〜/资源库/ LaunchAgents英寸本教程将告诉你如何创建许多不同种类的plist中的文件。一旦你添加你的plist到该文件夹​​,然后注销/登录,使之生效。要运行,然后从文件夹和注销/登录删除它禁用的plist外商投资企业。就这么简单。

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中,这一项将运行的AppleScript每60秒...

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>

所以,你只需把你的价值观com.myName.myProgramName,/path/to/applescript.scpt和60,这是运行的AppleScript的秒数的plist例子。

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天全站免登陆