修改Python脚本批量转换所有" WOFF"在目录文件 [英] Modify Python Script to Batch Convert all "WOFF" Files in Directory
问题描述
我一直使用由用户GitHub的一个@hanikesn伟大的开源python脚本(见下文)可以转换单一WOFF通过命令行(终端在Mac OS X)。文件恢复到OTF格式
I have been using a great open-source python script by GitHub user @hanikesn (see below) that converts a single WOFF file back into OTF format via command line (Terminal on Mac OS X).
因为它是现在,我拖 - 放脚本到终端,然后拖动和拖放一个WOFF文件到终端,preSS输入,脚本会在同一个目录中的OTF。该脚本可以手动调用,但我觉得它更容易和更快速地拖动和下降。但是作为一个印刷工人,我用大字体家庭工作,他们中的一些有每过100的风格,所以我需要一个批量转换工具。我知道有一些在线工具,但这些通常有大小限制,除非你支付服务,其结果是从来没有像这个脚本是一致的。此外,我想有一个离线工具。
As it is now, I drag-and-drop the script to Terminal, then drag-and-drop a WOFF file to Terminal, press Enter, and the script creates an OTF in the same directory. The script can be invoked manually, but I find it much easier and much faster to drag-and-drop. However as a typographer, I work with large font-families, some of them have over 100 styles each, so I need a batch conversion tool. I know there are some tools online, but these usually have a size limit unless you pay for the service, and the results are never as consistent as this script. Besides, I would like to have an offline tool.
我想修改它的某个目录(WOFFs的文件夹中),而不是一个单独的文件中运行。理想情况下,我想拖 - 放脚本到终端,然后拖动和拖放的文件夹。这个脚本应该只尝试转换文件的扩展.woff
I would like to modify it to run on a directory (folder of WOFFs) rather than a single file. Ideally I would like to drag-and-drop the script into terminal, and then drag-and-drop a folder. The script should only attempt to convert files with the .woff extension.
当我问剧本的创作者,他说:这可以很容易地用一个简单的一行shell脚本来完成:
When I asked the creator of the script, he said "This can easily be done with a simple one line shell script:
for file in *.woff; do woff2otf.py $file; done
不过,我不知道如何实现这一点。我不是一个程序员,但我已经在我的排版项目一些基本的Python脚本工作。所以,请解释给我就像我5。
However I don't know how to implement this. I am not a programmer, but I've had to work with some basic python scripting in my typography projects. So, please explain it to me like I'm 5.
推荐答案
如果你想创建一个拖放放大器;掉落的应用程序,你可以:
If you want create an Drag&drop app, you could:
- 打开Automator.app </ li>
- 选择应用程序
- 在左侧库找到
过滤器Finder项目
操作 - 将到右侧
- 添加
extenstion是
WOFF 状态 - 在图书馆找到
运行Shell脚本
操作 - 修改
通输入
弹出窗口的作为参数 - 将与放大器;降你的
woff2otf.py
到的回波的地方(你会得到它的全路径名) - 保存应用程序的某个地方为
woff2otf.app </ code>
- congratz - 你与你的第一个OS X应用程序完成的。 :)
- open the Automator.app
- select "Application"
- in the left-side Library find the
Filter Finder Items
action - drag it into the right
- add the
extenstion is
woff condition - in the Library find the
Run Shell Script
action - change the
Pass input
popup to as arguments - drag&drop the your
woff2otf.py
into the place of the echo (you will get it's full path name) - save the app somewhere as
woff2otf.app
- congratz - you're done with your 1st OS X application. :)
只需拖动 WOFF
文件放入应用程序图标,就应该对其进行转换。我无法测试它,因为我还没有安装 python3
。
Just drag the woff
files into the application icon and it should convert them. I can't test it, because i havent installed python3
.
最后的应用程序应该在下面的截图:
The final app should be as in the following screenshot:
编辑:
如果你的 python3
命令不是标准命令搜索 $ PATH
,您必须更改线路:
If your python3
command isn't in the standard command search $PATH
, you must change the line:
-
/path/to/the/woff2otf.py$ F
到 -
/路径/要/你/ python3 /path/to/the/woff2otf.py$ F
/path/to/the/woff2otf.py "$f"
to/path/to/your/python3 /path/to/the/woff2otf.py "$f"
我装 python3
使用 anyenv
- 例如它不会帮你。因此,我的python3是:
I installed python3
using anyenv
- e.g. it wont help you. Therefore my python3 is:
$ type python3
python3 is /opt/anyenv/envs/pyenv/shims/python3
所以在shell脚本的线(对我来说)是这样的:
so the line in the shell script (for me) looks like:
/opt/anyenv/envs/pyenv/shims/python3 ~/bin/woff2otf.py "$f"
不过,您的安装肯定是不同的。
But, your installation is surely different.
也可以帮助:
- 其中登录bash脚本或〜/ .profile文件MAC
- 检查从Bash脚本存在计划
- 如何ZSH编辑路径变量
- 如何显示zsh的函数定义(如bash的&QUOT;类型MYFUNC&QUOT;)?
- 放在什么地方$ PATH变量断言在zsh的?
- 更像上述
这篇关于修改Python脚本批量转换所有&QUOT; WOFF&QUOT;在目录文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!