python调用woff_修改Python脚本批量转换所有" WOFF"在目录文件

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).

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.

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.

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

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:

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. :)

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:

EDIT:

If your python3 command isn't in the standard command search $PATH, you must change the line:

/path/to/the/woff2otf.py "$f" to

/path/to/your/python3 /path/to/the/woff2otf.py "$f"

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

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.

Also could help:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值