Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Search for unused attachments in page

Hi All,

after having read this article, I wrote a short script to compare the filenames of the attachments actually used in a page with the filenames of the files actually attached to the page.

I'll make it then cycle through the various spaces to look for the many attcahments that users have been draggin in and then simply forgot there.

I still have to check for those attachments that are no more present in their storage page but maybe linked from some other page, even though I guess this should be a rare case.

As usual for me, it's not perfect/elegant & not finished, but it seems to do what I need.

If it can be of some start/help for anybody, then I'm happy.


import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.Attachment
import com.atlassian.confluence.pages.AttachmentManager
import org.jsoup.Jsoup

def pageManager = ComponentLocator.getComponent(PageManager)
def attachmentManager = ComponentLocator.getComponent(AttachmentManager)

//Aqcuisisco pagina
def page = pageManager.getPage('~MySpace', 'Check Attachments')
//Acquisisco contenuto pagina
def body = page.bodyContent.body

//Definisco lista allegati citati nella pagina
def usedAttachments=[]
//Definisco lista di tutti gli allegati della pagina
def existingAttachments=[]
//Definisco lista allegati non utilizzati
def unusedAttachments=[]

//Faccio un parse del contenuto pagina
def parsedBody = Jsoup.parse(body)
//Cerco blocco attachment
def attachments ="ri|attachment")
//Scorro tutti i blocchi attachment trovati
attachment ->

//Cerco allegati alla pagina
def loadedAttachments=attachmentManager.getLatestVersionsOfAttachments(page)

//Riordino le liste

//Controllo utilizzo

log.warn('Allegati alla pagina:')

log.warn('Presenti nella pagina:')

log.warn('Allegati non utilizzati nella pagina:')


Ciao, A



Dave Liao Community Leader Aug 29, 2020

@Andrea Boerio - grazie mille! 🙏 

This is a useful script for admins to houseclean and potentially free up storage capacity.

Like # people like this

Hi @Andrea Boerio

Thanks for sharing this script! I will pass this along to the rest of the ScriptRunner for Confluence team. We enjoy seeing how our users are utilizing SR - it is insightful for us. 😃



Like # people like this


Log in or Sign up to comment
Community showcase
Published in Confluence Cloud

🎨 Add some visual life to your templates

Hi Atlassian Community, My name is Avni Barman, and I am a Product Manager on the Confluence Cloud team. Based on feedback from you, we are giving admins more power to create templates that a...

102 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you