首页 > 解决方案 > 我的 AppleScript 运行这么慢是有原因的吗?

问题描述

我有一个从命令行提示符运行的脚本。该命令后跟一些文本,将在 Reminder.app 中设置一个提醒,截止日期为下周五。该脚本运行大约需要 100 秒,这似乎非常高。

on nextWeekday(wd)
    set today to current date
    set twd to weekday of today
    if twd is wd then
        set d to 7
    else
        set d to (7 + (wd - twd)) mod 7
    end if
    return today + (d * days)
end nextWeekday

on run argv
    set nextFriday to nextWeekday(Friday)
    tell application "Reminders"

        set newLable to argv as string

        set myList to list "Do."

        tell myList
            set newReminder to make new reminder
            set name of newReminder to newLable
            #set remind me date of newReminder to theDay
            set allday due date of newReminder to nextFriday
        end tell
    end tell
end run

.bash_profile 中的代码如下:

function reme() {
  cd
  cd /Users/jamieauburn/Documents/projects/reminder
  osax reme.scpt $1
}

我的剧本有问题吗?

标签: bashmacoscommand-lineapplescriptreminders

解决方案


你这里有很多不必要的东西。你的脚本可以写得更紧凑,速度提高了大约 4 倍。

on run argv
    tell (current date) to set nextFriday to it + (6 - (its weekday)) * days
    tell application "Reminders" to tell list "Do."
        make new reminder with properties {name:(argv as string), allday due date:nextFriday}
    end tell
end run

推荐阅读