StandardAdditions有path to命令,我们可以用它来获取已知的位置.
例如,path to home folder返回一个文件引用user folder,如果我们想要posix path,我们可以做POSIX path of ((path to home folder) as text).
在Terminal.app我们可以使用波浪号字符(~)来表示home folder.
我们怎样才能做到这一点tilde expanding的AppleScript?
入门OS X 10.10您可以轻松地访问Cocoa classes和它们的功能和特性:
use framework "Foundation"
expandTilde("~/Desktop")
on expandTilde(givenPath)
-- create a temporary Obj-C/Cocoa NSString object with the givenPath
set tempCocoaString to current application's NSString's stringWithString:givenPath
-- call the object's stringByExpandingTildeInPath method
-- to create a new path with expanded tilde
return (tempCocoaString's stringByExpandingTildeInPath) as string
end expandTilde
Run Code Online (Sandbox Code Playgroud)
在10.9你必须定义这样的处理程序Scripting Libraries,这不如听起来好.但在10.10这个开箱即用的工作!
| 归档时间: |
|
| 查看次数: |
551 次 |
| 最近记录: |