如何使用Applescript访问Finder中的隐藏文件?
问题描述:
defaults write com.apple.finder AppleShowAllFiles ON
现在,它的工作原理如何使用Applescript访问Finder中的隐藏文件?
tell application "Finder" to get folder ".spring" of home
#folder ".spring" of folder "username" of folder "Users" of startup disk of application "Finder"
...
defaults write com.apple.finder AppleShowAllFiles OFF
现在不
tell application "Finder" to get folder ".spring" of home
#Can’t get folder ".spring" of folder "username" of folder "Users" of startup disk of application "Finder"
我需要将文件复制到该位置。
答
如果可能,我会在这种情况下避免Finder。 do shell script
应该能够做你想做的。
tell application "Finder"
set fileToMove to choose file
set targetPath to "~/.spring"
set moveCmd to "mv '" & (POSIX path of fileToMove) & "' " & targetPath
do shell script moveCmd
end tell
使用bash是丑陋的,但我想它是有效的。我希望你可以做一些像“告诉finder获取隐藏文件”或其他系统事件的技巧。 – Pepijn 2010-02-07 16:50:13
确实如此,但我发现通常使用Applescript是最可靠的方法。在这种情况下,Finder会明确禁止看到不可见的文件(通过隐藏的'defaults'设置),因此无法访问该文件夹似乎是API设计者所期望的。 – 2010-02-08 18:54:44