V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
daniel1999
V2EX  ›  编程

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

  •  
  •   daniel1999 · 2019-08-02 12:32:10 +08:00 · 3620 次点击
    这是一个创建于 1728 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想做一个用 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

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

    重点大概是在 create note 命令后面加上 attachments <文件的 posix 路径>
    daniel1999
        2
    daniel1999  
    OP
       2019-08-02 14:18:38 +08:00
    @Sylv 感谢!我先研究一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5845 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 06:23 · PVG 14:23 · LAX 23:23 · JFK 02:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.