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

AppleScript 太鬼畜了

  •  
  •   geelaw · 2019-02-28 05:17:52 +08:00 · 3282 次点击
    这是一个创建于 1856 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近做了一个“在这里打开 PowerShell ”的菜单项,因为需要转义目录路径(例如 /path/"to`/file 需要变成 "/path/\"to\`/file"),又需要 tell application Terminal to do script 之类的,所以就自然用 AppleScript。

    如何替换字符串呢?官方文档 是这么写的:

    on findAndReplaceInText(theText, theSearchString, theReplacementString)
        set AppleScript's text item delimiters to theSearchString
        set theTextItems to every text item of theText
        set AppleScript's text item delimiters to theReplacementString
        set theText to theTextItems as string
        set AppleScript's text item delimiters to ""
        return theText
    end findAndReplaceInText
    

    这浓浓的“设置寄存器”“执行运算”“恢复寄存器”的感觉实在酸爽。

    最后是 广告时间

    在 macOS 文件上下文菜单中加入“用 Code 打开”和“在这里打开 PowerShell ”。

    这两段代码都发到对应产品的 GitHub issues 里面了。

    2 条回复    2019-02-28 07:21:34 +08:00
    discrete
        2
    discrete  
       2019-02-28 07:21:34 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3561 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 04:58 · PVG 12:58 · LAX 21:58 · JFK 00:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.