geelaw
V2EX  ›  macOS

AppleScript 太鬼畜了

  •  
  •   geelaw · Feb 28, 2019 · 4100 views
    This topic created in 2726 days ago, the information mentioned may be changed or developed.

    最近做了一个“在这里打开 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 里面了。

    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2987 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 03:50 · PVG 11:50 · LAX 20:50 · JFK 23:50
    ♥ Do have faith in what you're doing.