怎么在一个 AppleScript 里套用其他 AppleScript 的 handler/function/subroutine/method?

2014-06-17 20:34:22 +08:00
 qian
details: http://stackoverflow.com/questions/24262778/
2443 次点击
所在节点    问与答
4 条回复
orzfly
2014-06-17 22:35:13 +08:00
推荐把你的解决方法也发一下方便后人……
qian
2014-06-17 22:44:42 +08:00
@orzfly stackoverflow 那位仁兄已经帮忙解决了。额,我这边贴一下我稍微改动的 solution :

snippet 1

on removeText(unwanted, theText)
set {TID, text item delimiters} to {text item delimiters, unwanted}
set theText to text items of theText
set text item delimiters of AppleScript to ""
set theText to theText as text
set text item delimiters to TID
return theText
end removeText

on replaceText(unwanted, wanted, theText)
set {TID, text item delimiters} to {text item delimiters, unwanted}
set theText to text items of theText
set text item delimiters of AppleScript to wanted
set theText to theText as text
set text item delimiters to TID
return theText
end replaceText

把 snippet 1 保存到 Script Libraries (我没看懂 http://macosxautomation.com/mavericks/libraries/index.html 里在说什么,总之不算了我就在 ~/Library 新建名为“Script Libraries”的文件夹,把 text.scpt 放在里面)

以后有需复用 AS text manipulation snippet 的情况,我就把 snippet 扔 text.scpt 里。

实际使用肯定离不开 TextExpander (TE),在 TE 新建一个 AS 文件夹,再新建若干 rules:

ASreplace

tell script "text" to set theText to replaceText("%filltext:name=old%", "%filltext:name=new%", theText)

ASremove

tell script "text" to set theText to removeText("old", theText)

在 Hazel 用 AS 利用文件名和 AS text item delimiters 进行文件/文件夹 filing 时,有 TE 就方便许多。
qian
2014-06-17 22:45:32 +08:00
不算了 -> 不管了 (...
qian
2014-06-17 22:46:44 +08:00
...

ASremove

tell script "text" to set theText to removeText("%filltext:name=old%", theText)

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

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

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

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

© 2021 V2EX