在编写 Photoshop 脚本时打开文件夹中所有文件以 JPG 扩展名 [英] Open all files in folder with JPG extension while scripting Photoshop

查看:46
本文介绍了在编写 Photoshop 脚本时打开文件夹中所有文件以 JPG 扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在 Photoshop 中打开具有特定文件扩展名的所有文件,而不是使用 VBScript 打开单个文件名?或者,我可以使用 JS 函数来执行此操作吗?

Does anyone know how one might open in Photoshop all files with a particular file extension rather than individual file names using VBScript? Alternatively, could I use a JS function to do this?

推荐答案

如果我理解正确,VBScript 可用于通过 Windows Script Host 从外部自动化 Photoshop.

If I understand correctly, VBScript can be used to externally automate Photoshop, via the Windows Script Host.

因为您是从 Photoshop 应用程序外部运行 AppleScript 和 VBScript 脚本的,所以您的脚本应该做的第一件事是指示在 Photoshop 中执行的命令

Targeting and Referencing the Application object

Because you run your AppleScript and VBScript scripts from outside the Photoshop application, the first thing your script should do is indicate that the commands be executed in Photoshop

PDF 链接,第22

VBScript 可以访问 FileSystemObject 类型,它是 Microsoft Scripting Runtime 库的一部分.FileSystemObject 允许您遍历文件夹中的每个文件并检查扩展名.

VBScript can access the FileSystemObject type, which is a part of the Microsoft Scripting Runtime library. FileSystemObject allows you to iterate over each file in a folder and check the extension.

Option Explicit

Dim app
Set app = CreateObject("Photoshop.Application")

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fle
For Each fle In fso.GetFolder("c:\path\to\folder").Files
    If fso.GetExtensionName(fle.Path) = ".jpeg" Then

        'Issue the command to open the file in the default format
        'This uses the Open method from the Photoshop object model
        app.Open fle.Path

    End If
Next

参考文献:

请注意,可以在外部控制的 Javascript 文件中编写相同的代码:

Note that the same code could be written in an externally controlling Javascript file:

var app = new ActiveXObject('Photoshop.Application');
var fso = new ActiveXObject('Scripting.FileSystemObject');

var enumerator = new Enumerator(fso.GetFolder('c:\\path\\to\\folder').Files);
while (!enumerator.atEnd()) {
    var filepath = enumerator.item().Path;
    if (fso.GetExtensionName(filepath) == '.jpeg') {

        app.Open(filepath);

    }
    enumerator.moveNext();
}

但脚本指南中的示例使用的是内部执行的 Javascript 文件;它们必须保存在特定文件夹中,并且只能在应用程序打开后在应用程序上下文中运行.

but the examples in the Scripting Guide are using internally executing Javascript files; they must be saved in a specific folder, and can only be run once the application is open, and within the context of the application.

这篇关于在编写 Photoshop 脚本时打开文件夹中所有文件以 JPG 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆