Hi,
I need some help with a specific bulk-editing task.
I am now using a new set of attributes and would like to rename the attributes in my old listings without losing the data stored in their fields. To give you an example:
I currently have six attributes named A, B, C, D, E and F, which I would like to rename AA, BB, CC, DD, EE and FF, respectively.
However, if I select all my listings and use the checkbox to apply the new attribute names, GarageSale automatically overwrites the existing data in those fields. What I would like to do is simply rename the attributes while preserving all the information already stored in them. Is there any way to achieve this task in bulk, perhaps through ascript workaround or anything else?
Thank you in advance for your help!
I can’t promise anything but this could be doable with a simple script.
I will try to have a look at this later this day.
The following script should work as expected. At the top of the script you just have to adjust the attribute names in const RENAME
To use this script open GarageSale’s script editor, click the + button and paste the script. Select one or more listings in GarageSale’s main window, then click the “Run” button in script editor.
Please try it with two listings first to make sure it works for you. There is no undo function.
// GarageSale script: rename item specifics (attributes) in the selected listings
// while keeping their values.
//
// Edit the mapping below: "old name": "new name"
const RENAME = {
"A": "AA",
"B": "BB",
"C": "CC",
"D": "DD",
"E": "EE",
"F": "FF",
};
// If a listing already has an attribute with the new name:
// false = keep the existing value of the new attribute and drop the old one
// true = overwrite the new attribute with the value of the old one
const OVERWRITE_EXISTING = false;
function run() {
const answer = displayDialog(
"Rename attributes in " + selectedListings.length + " selected listing(s)?\n\n" +
Object.keys(RENAME).map(k => k + " → " + RENAME[k]).join("\n"),
"Rename", "Cancel");
if (answer !== "Rename") {
consoleLog("Cancelled.");
return;
}
let changedListings = 0;
for (const listing of selectedListings) {
const oldAttributes = listing.attributes;
const newAttributes = {};
let changed = false;
// Keep all attributes that are not being renamed
for (const name in oldAttributes) {
if (!(name in RENAME)) {
newAttributes[name] = oldAttributes[name];
}
}
// Move values from old names to new names
for (const name in oldAttributes) {
if (!(name in RENAME)) continue;
const newName = RENAME[name];
if (newName in newAttributes && !OVERWRITE_EXISTING) {
consoleLog(listing.title + ": \"" + newName + "\" already exists, kept its value, removed \"" + name + "\"");
} else {
newAttributes[newName] = oldAttributes[name];
}
changed = true;
}
if (changed) {
listing.attributes = newAttributes;
changedListings++;
consoleLog("Updated: " + listing.title);
}
}
consoleLog("Done. " + changedListings + " of " + selectedListings.length + " listing(s) changed.");
}