请教一个关于 AppleScript 写的自动化处理脚本

2019-08-02 12:32:10 +08:00
 daniel1999
我想做一个用 AppleScript 写的自动化处理脚本,找了好久没找到方法,我的需求是这样的,我想在 Mac 上选中一个文本或者文件,用一个快捷键触发 automator 的脚本,然后在印象笔记某个指定的笔记本下创建一条笔记。我现在用 AppleScript 只能做到保存文本,文件不知道该怎么做。下面是我目前写的一个脚本。

on run {input}

set selectedText to first item of input
set {year:y, month:m} to current date
set noteTitle to y & "年" & m * 1 & "月" as string
display notification selectedText & " 已加入" & noteTitle & "待整理" with title "保存成功"

tell application "印象笔记"
try

create note title noteTitle with html "<div>" & selectedText & "</div>" notebook "待整理"

synchronize

on error errMsg
display dialog "哦,出了点小问题:
" & errMsg
end try
end tell
end run

目前只能保存选中的文档到印象笔记,请教大家,怎么做到选中文件也能自动创建带附件的笔记。
3653 次点击
所在节点    编程
2 条回复
Sylv
2019-08-02 13:56:08 +08:00
搜了下,查到这个,你可能可以参考一下?
https://gist.github.com/JMichaelTX/b27c829d94797462a597913d6e1e195f

重点大概是在 create note 命令后面加上 attachments <文件的 posix 路径>
daniel1999
2019-08-02 14:18:38 +08:00
@Sylv 感谢!我先研究一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/588489

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX