AppleScript 太鬼畜了

2019-02-28 05:17:52 +08:00
 geelaw

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

3309 次点击
所在节点    macOS
2 条回复
discrete
2019-02-28 07:10:50 +08:00
discrete
2019-02-28 07:21:34 +08:00

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

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

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

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

© 2021 V2EX