The eagle.smartFolder API lets you create, query, modify, and delete smart folders.
Version Requirement: This feature requires Eagle 4.0 build22 or later.
// Create a smart folder using the fluent builderconstsf=awaiteagle.smartFolder.create({name:'Large PNGs',conditions: [eagle.smartFolder.Condition.create('AND', [eagle.smartFolder.rule('width')['>']([1920]),eagle.smartFolder.rule('type').equal('png'), ]) ]});// Modify propertiessf.name='Extra Large PNGs';sf.iconColor='blue';// Save changesawaitsf.save();
🦄 Best Practice: Use the getRules() method to get all available filter rule schemas. Combined with the rule() fluent builder and Condition.create() helper, you can construct conditions more safely.
Methods
create(options)
Create a smart folder
options Object
name string - Smart folder name
conditions Object[] - Filter conditions
description string (optional) - Description
iconColor string (optional) - Icon color
parent string (optional) - Parent smart folder ID
Returns Promise<smartFolder: SmartFolder> - The newly created smart folder
get(options)
Get smart folders matching the specified criteria.
options Object - Query criteria
id string (optional) - Smart folder ID
ids string[] (optional) - Array of smart folder IDs
Tip: Call getRules() first to get available properties and methods, then use the rule() builder to construct conditions safely.
rule(property)
Fluent builder for constructing a single filter rule. Returns an object with all available methods; calling a method produces the corresponding Rule object.
// Name contains "cat"
eagle.smartFolder.rule('name').contain('cat');
// Width greater than 1920
eagle.smartFolder.rule('width')['>']([1920]);
// Type equals png
eagle.smartFolder.rule('type').equal('png');
// Rating greater than or equal to 3
eagle.smartFolder.rule('rating')['>=']([3]);
// Name is empty
eagle.smartFolder.rule('name').empty();
// Used with Condition.create
let condition = eagle.smartFolder.Condition.create('AND', [
eagle.smartFolder.rule('name').contain('cat'),
eagle.smartFolder.rule('width')['>']([1920]),
]);
let sf = await eagle.smartFolder.getById('smart_folder_id');
console.log(sf.id);
console.log(sf.name);
sf.name = 'New Name';
console.log(sf.name);
await sf.save();
let sf = await eagle.smartFolder.getById('smart_folder_id');
sf.name = 'New Name';
sf.iconColor = 'green';
// Save changes
await sf.save();
let sf = await eagle.smartFolder.getById('smart_folder_id');
// Get all matching items
let items = await sf.getItems();
// Specify return fields
let items2 = await sf.getItems({
fields: ['id', 'name', 'ext', 'width', 'height']
});
let sf = await eagle.smartFolder.getById('smart_folder_id');
// Set icon color to red
sf.iconColor = eagle.smartFolder.IconColor.Red;
// Or use a string value directly
sf.iconColor = 'red';
// Save changes
await sf.save();
let children = sf.children;
console.log(children[0].name);
// Create via constructor
let rule = new eagle.smartFolder.Rule('name', 'contain', 'cat');
// Or use the rule() fluent builder (recommended)
let rule2 = eagle.smartFolder.rule('name').contain('cat');
// Create using Condition.create
let condition = eagle.smartFolder.Condition.create('AND', [
eagle.smartFolder.rule('name').contain('cat'),
eagle.smartFolder.rule('width')['>']([1920]),
]);
// Create an exclusion condition
let excludeCondition = eagle.smartFolder.Condition.create('OR', [
eagle.smartFolder.rule('type').equal('gif'),
], 'FALSE');