Apple Automator 处理 csv 文件并创建新文件
是否可以使用 Apple Automator 循环遍历一组选定的文件,处理每个文件,然后将输出保存为新文件?
我有一组 .xls 文件,并且已经使用 Automator
- Ask for Finder Items
- Open Finder Items
- Convert Format of Excel Files #save each .xls file to a .csv
编写了一个 python 脚本,该脚本接受文件名作为参数,对其进行处理,并将其作为 p_filename 保存在脚本运行的目录中。我正在尝试将 Run Shell Script
与 /usr/bin/python
shell 和粘贴的 python 脚本一起使用。
不过,有些东西翻译得不太好,特别是因为我不确定它如何处理 python 的 open('filename','w') 命令。它可能没有创建新文件的权限,或者我输入的命令不正确。我的想法是将处理后的文件输出为文本,使用 Automator 捕获它,然后将其保存到新文件中。
为此,我尝试使用新建文本文件
,但我无法让它为开始时选择的每个文件创建一个新的文本文件。是否可以循环浏览所有选定的 Finder 项目?
Is it possible to loop through a set of selected files, process each, and save the output as new files using Apple Automator?
I have a collection of .xls files, and I've gotten Automator to
- Ask for Finder Items
- Open Finder Items
- Convert Format of Excel Files #save each .xls file to a .csv
I've written a python script that accepts a filename as an argument, processes it, and saves it as p_filename in the directory the script's being run from. I'm trying to use Run Shell Script
with the /usr/bin/python
shell and my python script pasted in.
Some things don't translate too well, though, especially since I'm not sure how it deals with python's open('filename','w')
command. It probably doesn't have permissions to create new files, or I'm entering the command incorrectly. I had the idea to instead output the processed file as text, capture it with Automator, and then save it to a new file.
To do so, I tried to use New Text File
, but I can't get it to create a new text file for each file selected back in the beginning. Is it possible to loop through all the selected Finder Items?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要在脚本文件夹中完成此操作?或者您是指从 Finder 项目中获取的文件的文件夹?在这种情况下,只需获取传递到 Python 的每个文件的路径即可。
当您运行 open('filename','w') 时,您应该传入完整路径名。可能发生的情况是您实际上正在写入根目录,而不是您认为的位置。
假设您将文件作为参数传递给 Automator 中的 shell 命令,那么您可能会遇到以下情况:
Why do you want this done in the folder of the script? Or do you mean the folder of the files you are getting from the Finder items? In that case just get the path for each file passed into Python.
When you run open('filename','w') you should thus pass in a full pathname. Probably what's happening is you are actually writing to the root directory rather than where you think you are.
Assuming you are passing your files to the shell command in Automator as arguments then you might have the following: