扩大与preFIX&QUOT一个POSIX路径;〜" (使用AppleScript) [英] Expand a POSIX path with prefix "~" (using AppleScript)
问题描述
StandardAdditions
的<一个href=\"https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW19\"相对=nofollow称号=的AppleScript语言指南> 路径
命令,我们可以用它来获得已知位置。
StandardAdditions
has the path to
command and we can use it to get known locations.
例如,路径,主文件夹
返回文件参照用户文件夹
,如果我们希望 POSIX路径
,我们可以做((路径,主文件夹)文本)
。
For example, path to home folder
returns a file reference to the user folder
and if we want the posix path
, we can do POSIX path of ((path to home folder) as text)
.
在 Terminal.app </ code>我们可以使用波浪号字符(
〜
)重新present的主文件夹
。
In Terminal.app
we can use the tilde character (~
) to represent the home folder
.
我们怎样才能做到这一点波浪在
的AppleScript
?
How can we do this tilde expanding
in AppleScript
?
推荐答案
入门 OS X 10.10
您可以轻松地访问 Cocoa类
和它们的功能和属性:
Started with OS X 10.10
you can easily access Cocoa classes
and their functions and properties:
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
在 10.9
您在来定义这样的处理程序脚本库
,这比它听起来不错少。但在 10.10
这个作品开箱!
In 10.9
you have to define such handlers in Scripting Libraries
, that's less nice than it sounds. But in 10.10
this works out of the box!
这篇关于扩大与preFIX&QUOT一个POSIX路径;〜&QUOT; (使用AppleScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!