Hey everyone! I’m trying to figure out how to run a script when a user makes changes to a Google Doc. I know Google Apps has some built-in triggers, and there’s an onEdit trigger for Spreadsheets. But it looks like that doesn’t work for Docs.
Does anyone know a good way to detect when someone edits a Google Doc and then run a script automatically? I’m hoping for something simple and straightforward. Maybe there’s a different kind of trigger or event we can use?
I’d really appreciate any tips or ideas! Thanks in advance for your help.
hey elizabeths, unfortunatly theres no built-in trigger for docs like spreadsheets but u could try using the google docs api to periodically check for changes. its not perfect but might work 4 ur needs. good luck!
I’ve been working with Google Docs automation for a while, and you’re right - there’s no direct equivalent to the onEdit trigger for Docs. However, I’ve found a workaround that might help. You can use time-based triggers to run a script at regular intervals. In your script, you can compare the current state of the document to a previously saved state to detect changes.
Here’s a rough outline of the approach:
Save the document’s content as a property
Set up a time-based trigger to run every few minutes
In the triggered function, compare the current content to the saved content
If there’s a difference, run your desired actions and update the saved content
It’s not real-time, but it’s the closest I’ve found to achieving what you’re after. Just be mindful of quotas and performance if you’re dealing with large documents or frequent updates.