Yes, you can use this code to auto-pause at 5 PM and auto-enable at 9 AM.
What it does: Pauses selected campaigns at 17:00 and enables them at 09:00 (account time zone).
Safety: Only touches campaigns labeled AUTO_SCHEDULE. (Change or remove the label logic if you want it to affect all campaigns.)
Scheduling: Set the script to run Hourly.
/**
* Auto-pause at 17:00 and auto-enable at 09:00 (account time zone).
* Affects only campaigns with label "AUTO_SCHEDULE".
* Schedule: Hourly
*/
function main() {
var tz = AdsApp.currentAccount().getTimeZone();
var hour = parseInt(Utilities.formatDate(new Date(), tz, 'H'), 10); // 0–23
var labelName = 'AUTO_SCHEDULE';
ensureLabel_(labelName);
if (hour === 17) {
// 5 PM — pause enabled campaigns
var it = AdsApp.campaigns()
.withCondition("Status = ENABLED")
.withCondition("LabelNames CONTAINS_ANY ['" + labelName + "']")
.get();
var count = 0;
while (it.hasNext()) { it.next().pause(); count++; }
Logger.log('Paused ' + count + ' campaign(s) at 17:00.');
} else if (hour === 9) {
// 9 AM — enable paused campaigns
var it2 = AdsApp.campaigns()
.withCondition("Status = PAUSED")
.withCondition("LabelNames CONTAINS_ANY ['" + labelName + "']")
.get();
var count2 = 0;
while (it2.hasNext()) { it2.next().enable(); count2++; }
Logger.log('Enabled ' + count2 + ' campaign(s) at 09:00.');
} else {
Logger.log('No action this hour (' + hour + ':00).');
}
}
function ensureLabel_(name) {
if (!AdsApp.labels().withCondition("Name = '" + name + "'").get().hasNext()) {
AdsApp.createLabel(name);
}
}
How to use
In Google Ads: Tools & Settings → Bulk actions → Scripts → +
Paste the code → Authorize → Save.
Add the label AUTO_SCHEDULE to any campaign you want the script to control.
Schedule the script Hourly.