如何使用 appscript 和 Python 将文件列表输入到应用程序中?
拿起你的新手盾牌,我要给你洒一些。
我正在尝试让 Photoshop CS4 使用 AppScript+Python 打开一个包含 JPEG 图像的文件夹,这可以在 BASH 中这样描述:
#!/bin/bash
for F in `ls ~/Desktop/test`; do
open -a "Adobe Photoshop CS4" $F
# proceed to mutilate the image appearance
done
我在 ls ~/Desktop/test
阶段失败了。我真的很想让 Finder 为我列出一个文件夹,然后一次将结果输入 Photoshop 中进行处理。
与 Adobe 的 ExtendScript 桥等效的 JavaScript 是:
#target photoshop
var folder = Folder("~/Desktop/test");
var images = folder.getFiles();
for (var i=0; i < images.length; i++) {
if (images[i] instanceof File && images[i].hidden == false) {
var doc = app.open(images[i]);
// do something to the image here
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
我可以通过像 x = app('Finder').home.folders['Desktop'] 这样非常愚蠢的装置获得一个
,但事实证明这是一个非常愚蠢的对象。尝试document_file
对象。 ().folders['test']().items()[0]app('Adobe Photoshop CS4').open(x)
此对象将抛出OSERROR:1230
,并显示MESSAGE:需要文件/文件夹< /代码>。
(呃哦,这个 document_file
实际上响应 URL()
,所以 File.makewithurl(x.URL())
可以被输入到 open()
)
嗯,解决了这个问题,有没有办法通过向 Finder 询问给定文件夹中的文件列表来实际做到这一点,该文件夹由 指定>UNIX 路径?
Get your newb-shields up, I'm about to sprinkle you with some.
I'm trying to get Photoshop CS4 to open a folderful of JPEG images with AppScript+Python, which could be described like so in BASH:
#!/bin/bash
for F in `ls ~/Desktop/test`; do
open -a "Adobe Photoshop CS4" $F
# proceed to mutilate the image appearance
done
I'm failing at the ls ~/Desktop/test
stage. I'd really like to ask Finder to list a folder for me, and feed the result into Photoshop one at a time to process them.
A JavaScript equivalent with Adobe's ExtendScript bridge would be:
#target photoshop
var folder = Folder("~/Desktop/test");
var images = folder.getFiles();
for (var i=0; i < images.length; i++) {
if (images[i] instanceof File && images[i].hidden == false) {
var doc = app.open(images[i]);
// do something to the image here
doc.close(SaveOptions.DONOTSAVECHANGES);
}
}
I can get me a document_file
object with a horribly silly contraption like x = app('Finder').home.folders['Desktop']().folders['test']().items()[0]
, but that turns out to be a really silly object. Trying to app('Adobe Photoshop CS4').open(x)
this object will throw an OSERROR: 1230
, with a MESSAGE: File/Folder expected
.
(Uh-oh, this document_file
actually responds to URL()
, so File.makewithurl(x.URL())
can be fed into open()
)
Ehm, having solved that, is there a way to actually do this by asking Finder for the list of files in a given folder, specified by a UNIX path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Photoshop 的打开命令需要别名对象(或别名对象列表)。
Photoshop's open command requires an alias object (or list of alias objects).