使用Applescript打开用户的库文件夹

时间:2014-05-13 13:40:39

标签: applescript

我想打开默认为应用程序设置文件夹的文件夹:

/Users/XXX/Library/Application Support/Tunnelblick/Configurations

我不想'硬编码''XXX'。

/library文件夹:

set theDestination to (choose folder with prompt "Open destination folder" default location (path to library folder))

home文件夹:

set theDestination to (choose folder with prompt "Open destination folder" default location (path to home folder))

我不确定如何获取~/Library文件夹及其子文件夹之一。

3 个答案:

答案 0 :(得分:3)

图书馆的路径是:

POSIX path of (path to library folder from user domain)

=〜/ Library /

POSIX path of (path to library folder from local domain)

= / Library /

POSIX path of (path to library folder from system domain)

= / System / Library /

答案 1 :(得分:1)


系统也知道应用程序支持文件夹:

set aFolderPath to ((path to application support folder from user domain) as text) & "Tunnelblick:Configurations:"
try
    set destinationPath to aFolderPath as alias
on error
    beep
    log aFolderPath & " missing"
    return
end try
set theDestination to (choose folder with prompt "Open destination folder" default location destinationPath)



请参阅StandardAdditionspath to

path to v : Return the full path to the specified folder
path to application support/applications folder/desktop/desktop pictures folder/documents folder/downloads folder/favorites folder/Folder Action scripts/fonts/help/home folder/internet plugins/keychain folder/library folder/modem scripts/movies folder/music folder/pictures folder/preferences/printer descriptions/public folder/scripting additions folder/scripts folder/services folder/shared documents/shared libraries/sites folder/startup disk/startup items/system folder/system preferences/temporary items/trash/users folder/utilities folder/workflows folder/voices/apple menu/control panels/control strip modules/extensions/launcher items folder/printer drivers/printmonitor/shutdown folder/speakable items/stationery : the folder to return
[from system domain/local domain/network domain/user domain/Classic domain] : where to look for the indicated folder
[as type class] : the type to return: alias or string (default is alias)
[folder creation boolean] : Create the folder if it doesn’t exist? (default is true)
→ alias : the path to the specified folder

答案 2 :(得分:0)

解决:

set theDefault to (path to home folder as text) & "Library:Application Support:Tunnelblick:Configurations" as alias

set theDestination to (choose folder with prompt "Open destination folder" default location theDefault)