const ps=Application('Adobe Photoshop 2021')
ps.doJavascript('alert(1)', [1, 2, 3], 'before running')
ps.backgroundColor.properties() //get
// =>{red: 0, green: 0, blue: 0}
ps.backgroundColor.red = 10 //set
ps.foregroundColor.properties() //get
// =>{red: 0, green: 0, blue: 0}
ps.foregroundColor.red = 10 //set
ps.currentDocument.properties()
// {backgroundLayer: function, bitsPerChannel: "eight", colorProfileKind: "working", colorProfileName: "sRGB IEC61966-2.1", mode: "RGB", …}
ps.currentTool()
// sliceTool
ps.currentTool = 'moveTool' //set
ps.displayDialogs
ps.displayDialogs = 'always' //erro dialogs / never / always
ps 支持的文件类型数组
ps.macintoshFileTypes()
// ["8BPS", "8BPB", "8BIM", "8BIM", "8BIM", "8BIM", "8BIM", "8BIM", "8BIM", "8BIM", …] (46)
ps.systemInformation()
// "Adobe Photoshop 版本: 22.0.0 20201006.r.35 2020/10/06: 4587a1caa63 x64...
const se = Application('System Events')
se.processes
.byName(this.app.name())
.menuBars[0].menuBarItems[2].menus[0].menuItems.name()
// => ["新建...", "打开...", "在 Bridge 中浏览...", "打开为智能对象...", "最近打开文
获取字体,不能使用中文搜索
ps.fonts.whose({ name: { _contains: 'Noto Sans S Chinese' } }).name()
// ["Noto Sans S Chinese Thin", "Noto Sans S Chinese Light", "Noto Sans S Chinese DemiLight", "Noto Sans S Chinese Regular", "Noto Sans S Chinese Medium", "Noto Sans S Chinese Bold Bold", "Noto Sans S Chinese Black Bold"] (7)
打开文件选择界面,返回文件列表
ps.photoshopOpenDialog()
batch text : the name of the action to play (note that the case of letters in the Action name is important and must match the case of the name in the Actions palette)
ps.batch(‘test’,[],‘默认动作’)
fromFiles: list of alias : list of input files to operate on
from: text : the name of the action set containing the action being played (note that the case of letters in the Action Set name is important and must match the case of the name in the Actions palette)
[withOptions: BatchOptions] : options for Batch
→ text : run the batch automation routine
changeMode Document : the document object or objects to be operated upon
to: “bitmap”/"CMYK"/"grayscale"/"indexed color"/"Lab"/"multichannel"/"RGB" : name of mode to change to
[withOptions: ChangeModeOptions] : options for changing the mode
ps.currentDocument.changeMode({to:'CMYK'})
convertToShape method : converts the text object and its containing layer to a fill layer with the text changed to a clipping path
convertToShape Text-object : the text-object object or objects to be operated upon
ps.currentDocument.layers.whose({kind:'=text'})[0].convertToShape()
失败
ps.currentDocument.crop({bounds:[100,100,100,100]})
export method
export Document : the document object or objects to be operated upon
in: file specification : the file to export to
[as: “Illustrator paths”/"save for web"] : the type of export ( default: Illustrator paths )
[withOptions: ExportOptions] : options for the export type specifie
ps.currentDocument.export({in:'/Users/luomingyang/Desktop/test.png',as:'save for web'})
翻转画布,参数: “horizontal”/"vertical"
ps.currentDocument.flipCanvas({direction:'horizontal'})
当使用ps.settings.properties()
时,ps 会崩溃,尽量避免使用该命令
const doc=ps.currentDocument()
ps.currentDocument.layers[0].link({with:ps.currentDocument.layers[1]})
ps.currentDocument.mergeVisibleLayers()
backgroundLayer
currentLayer(set)
filePath
height
width
info
doc.info.properties()
// {title: "", author: "", authorPosition: "", caption: "", captionWriter: "", …} = $3
selection
获取选区信息
doc.selection.properties()
// {bounds: [56, 62, 141, 190], solid: true, container: function, bestType: "specifier", defaultType: "specifier", …}
以下对象都具有(get/make/delete)的方法
artLayer
channel
colorSampler
countItem
historyState
layer
layerComp
layerSet
pathItem
ps.currentDocument.artLayers.properties()
// {fillOpacity: 100, grouped: false, backgroundLayer: false, pixelsLocked: false, positionLocked: false, …}
// 1 {fillOpacity: 100, grouped: false, backgroundLayer: false, pixelsLocked: true, positionLocked: false, …}
// ...
相比与 layers 的区别是没有图层组的信息
ps.currentDocument.layers.properties()
// => {enabledChannels: Array, name: "组 1", allLocked: false, blendMode: "pass through", linkedLayers: [], …}
// 1 {fillOpacity: 100, grouped: false, backgroundLayer: false,
commands
ps.currentDocument.close({saving:'no'})//ask,yes,no
duplicate specifier : the object(s) to duplicate
[to: location specifier] : the new location for the object(s)
[withProperties: record] : new values for the properties of the duplicated element
ps.currentDocument.duplicate()
ps.currentDocument.duplicate({})
initialFill (“transparent”/"use background color"/"white", r/o) : initial fill of the document. Only valid when used as an option with the ‘make new document’ command
const app=require('photoshop').app
app.actionTree.forEach((item) => {
console.log(item.name)
})
// => 默认动作 \(index):1 裁剪图片\设计助理预设动作库
const doc=app.activeDocument
batchPlay(commands: any, options: any)
let newDoc1 = app.createDocument() // creates a 2100px * 1500px document
let newDoc2 = app.createDocument({
width: 800,
height: 600,
resolution: 300,
mode: 'RGBColorMode',
fill: 'transparent',
})
let newDoc3 = app.createDocument({ preset: 'My Default Size 1' })
ø
// Open a file given entry
let entry = await require('uxp').storage.localFileSystem.getFileForOpening()
const document = await app.open(entry)
// Show open file dialog
const document = await app.open()
需要注意:传入参数必须是字符串,否则不会生效,也不会返回错误信息
const ps = require('photoshop').app
ps.showAlert('1')
app.actionTrees[0].actions[0].play()
navigator.clipboard.setContent({"text/plain": "Hello!"});
navigator.clipboard.writeText('text');
navigator.clipboard.clearContent();
const res_obj = await navigator.clipboard.getContent()
const res = res_obj['text/plain']
eval(res)
插件重新加载数据依然存在
window.localStorage.setItem('name','uxp')
window.localStorage.getItem('name')
window.localStorage.removeItem('name')
window.localStorage.clear()
在插件生命周期内存在,插件卸载之后,数据会一同被清理,使用方法同 localStorage 一致
window.location.reload()
重新加载窗口
const os = require('os')
os.platform()
获得当前操作系统的名称,如:“win10”, “darwin”
获得系统版本号,如:20.2.0
获得系统的架构,如:x64
用于打开链接(url)
require('uxp').shell
shell.openExternal('https://www.baidu.com')
Adobe UXP: Things you need to know! #4 Panels vs. Commands and the manifest.json - YouTube