bash - 我的 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
}
我的剧本有问题吗?
解决方案
你这里有很多不必要的东西。你的脚本可以写得更紧凑,速度提高了大约 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
推荐阅读
- android - 无法通过我的应用在 android 电视中播放 youtube 视频 - “需要更新服务版本”
- java - 无法解析的日期格式
- html - 在jquery中编辑滚动位置
- c - Valgrind:条件跳转取决于堆栈分配创建的未初始化值
- android - 如何在另一个布局下部分获取布局
- python - 将二进制转换为字符串,然后使用 python 再次返回
- react-admin - React Admin - 根据其他资源为过滤器输入
- javascript - 合并相同长度的json
- reactjs - axios post 方法只是没有响应任何东西
- playframework - 在模块中播放 WS 客户端