Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save p4535992/3a570ba5f27f0e5a3b572431c82d5fb0 to your computer and use it in GitHub Desktop.
Save p4535992/3a570ba5f27f0e5a3b572431c82d5fb0 to your computer and use it in GitHub Desktop.
Change the permissions of items in bulk in FoundryVTT.
var folderName = "Test";
var reqPermission = 0; // 0=None, 1=Limited, 2=Observer, 3=Owner
/*****
WARNING: This will overwrite the permissions of the items in the folder <folderName>!
That is, it will not keep the player permissions!
Tested on FoundryVTT 0.5.5
******/
function repermission(currentFolder) {
console.log("Repermissioning: ", currentFolder.name);
if (currentFolder.content){
currentFolder.content.map(item => {
let newPermissions = duplicate(item.data.permission);
newPermissions.default = reqPermission;
console.log(" Item:", item.data.name);
item.update({permission: newPermissions});
});
}
if (currentFolder.children) {
currentFolder.children.map(({data}) => {
repermission(game.folders.entities.filter(f => f.data._id == data._id)[0]);
});
}
}
// select folder to re-permission
var rootFolder = game.folders.entities.filter(({data}) => data.name == folderName)[0];
repermission(rootFolder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment