使用 applescript 列出子文件夹
这是我的第一个苹果脚本。我以为我会做一些简单的事情,比如使用路径导航到文件夹并列出子文件夹...不幸的是,我无法弄清楚:-)
这是我迄今为止尝试过的:
第一次尝试:
tell application "Finder"
set the_folder to POSIX path of "Users:MyName:Doc"
log the_folder
set folder_list to every item of folder the_folder
log folder_list
end tell
这个产生错误: “Finder 出现错误:无法获取文件夹“/Users/MyName/Doc”。
有人可以吗: 1. 向我解释我做错了什么。 2. 提供一个可行的例子。
提前致谢。
顺便说一句,该文件夹确实存在于我的机器上......
This is my first applescript. I thought I'd do something simple like navigating to a folder using a path and listing the subfolders...Unfortunately, I can't figure it out :-)
Here is what I've tried so far:
The first try:
tell application "Finder"
set the_folder to POSIX path of "Users:MyName:Doc"
log the_folder
set folder_list to every item of folder the_folder
log folder_list
end tell
This produces an error:
"Finder got an error: Can't get folder "/Users/MyName/Doc".
Could someone please:
1. Explain to me what I'm doing wrong.
2. Provide an example that works.
Thanks in advance.
btw the folder does exist on my machine...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:哎呀!看来我给你的信息是错误的,所以我会给你正确的信息。
命令
POSIX path of
需要完整的别名引用。我的意思是提供完整的文件引用(即:Users::somefolder:
)。如果您引用的是文件夹,请确保以冒号结束引用(即Macintosh HD:Users:
)。改进的版本如下所示:可选
将
POSIX
路径(即/Users//somefolder
)强制返回别名
>,需要两次转换。转换 1:第一步是将引用转换为文件引用。为此,请将单词
as POSIX file
放在引用后面,如下所示:此代码生成以下形式的文件引用:
file ":Users::somefolder:"
转换 2:在引用末尾添加第二个强制转换,
as alias
...此代码生成一个实际的别名引用:
alias ":Users::somefolder:
如果您有任何疑问,请询问。:)
UPDATE: Oops! It appears that I have given you the wrong information so I will give you the correct information.
The command
POSIX path of
requires a complete alias reference. By that I mean supplying the full file reference (i.e.<your_disk_name>:Users:<your_user_name>:somefolder:
). Make sure that if you're referring to a folder that you end the reference with a colon (i.e.Macintosh HD:Users:
). An improved version would look like this:OPTIONAL
To coerce a
POSIX
path (i.e./Users/<your_user_name>/somefolder
) back into analias
, two conversions are needed.Conversion 1: The first step is to convert the reference into a file reference. To do this, place the words
as POSIX file
after the reference, like so:This code procudes a file reference in this form:
file "<your_disk_name>:Users:<your_user_name>:somefolder:"
Conversion 2: Add a second coercion,
as alias
, to the end of the reference...This code produces an actual alias reference:
alias "<your_disk_name>:Users:<your_user_name>:somefolder:
If you have any questions, just ask. :)
Posix 路径是您在命令行中使用的路径,并以“/”分隔。 Applescript 路径以“:”分隔,因此只需使用它们即可。尝试这个脚本看看路径应该是什么样子......
Posix paths are paths you use at the command line and are "/" delimited. Applescript paths are ":" separated so just use those. Try this script to see what the path should look like...