您的位置:首页 > 运维架构

Photoshop脚本 > 设置前景色和背景色

2017-05-26 16:41 309 查看
源自:http://coolketang.com/tutorials/menu1lesson8.php
本节将演示如何使用脚本,设置Photoshop的前景色和背景色。首先创建一个空白的脚本文档,并保存在硬盘上某个位置。并输入脚本代码:
var answer = confirm("您需要随机设置前景色和背景色吗?");
[confirm]命令会弹出一个包含[是/否]的确认框,由用户决定是否执行某一个操作。
选择的结果[是/否]将保存在[answer]变量里。

if(answer)
{
app.foregroundColor.rgb.red   = Math.random() * 255;
app.foregroundColor.rgb.green = Math.random() * 255;
app.foregroundColor.rgb.blue  = Math.random() * 255;
app.backgroundColor.rgb.red   = Math.random() * 255;
app.backgroundColor.rgb.green = Math.random() * 255;
app.backgroundColor.rgb.blue  = Math.random() * 255;
}
判断用户的选择,如果用户选择[是],则执行接下来的动作。
然后就可以设置Photoshop前景色和背景色了。
[Math.random]命令会生成一个0至1之间的随机值,随机值乘以255则生成0-255之间的随机值。完整的脚本文件:
var answer = confirm("您需要随机设置前景色和背景色吗?");

if(answer) { app.foregroundColor.rgb.red = Math.random() * 255; app.foregroundColor.rgb.green = Math.random() * 255; app.foregroundColor.rgb.blue = Math.random() * 255; app.backgroundColor.rgb.red = Math.random() * 255; app.backgroundColor.rgb.green = Math.random() * 255; app.backgroundColor.rgb.blue = Math.random() * 255; }


我们的脚本已经编写完成,现在把它保存下来。然后切换到Photoshop,然后依次点击[文件] > [脚本] > [浏览],打开刚刚保存的脚本文件。Photoshop将直接调用并执行该脚本。

在弹出的[脚本警告]弹出框窗口,点击[是]按钮,开始设置前景色和背景色,请留意工具条下方前景色和背景色的变化。

















内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Photoshop 脚本 ps脚本