GUI Applescript for Chrome help

I’m trying to do a GUI Applescript for Google Chrome to “Clear Browsing Data…”

I can get the “Clear Browsing Data…” window to pop up but I’m unable to have applescript click the “clear browsing data” button. I tried Apples GUI scripting tool but I still couldn’t figure it out. Does anyone know the right code to get the script to click that button?
chanamasala is offline Reply With Quote

I don’t use that app, however this might work…

tell application “Google Chrome” to activate
tell application “System Events”
tell process “Google Chrome”
click first button of window 1 whose title is “clear browsing data”
end tell
end tell

Make sure the button title is correct with the correct capitalization and such. Also you may have to change the word “title” to “name”.

Thanks a bunch. It worked.

Here’s the full Applescript if anyone is interested.

(Sorry for Caps, but:)

WARNING!!! THIS CLEARS ANY BROWSING DATA YOU HAVE CHECKED IN THAT BOX!!! Don’t test/use unless you understand and know what that means. You can/will lose data, form info, passwords etc!!!


tell application "Google Chrome" to activate
tell application "System Events"
	key code 51 using {command down, shift down}
	tell process "Google Chrome"
		click (first button of window 1 whose title is "clear browsing data")
	end tell
end tell

Glad to help! :slight_smile: Good luck.

Here is another version if you want to do a big reset(close all windows in Chrome and then open another and then clear data) with a MacBook 15" screen:

tell application "Google Chrome" to activate
tell application "System Events"
	key code 13 using {command down, option down}
	delay 0.55
	key code 45 using {command down}
	delay 0.55
end tell
tell application "Google Chrome"
	tell first window
		set bounds to {0, 0, 1280, 800}
	end tell
end tell
tell application "System Events"
	key code 51 using {command down, shift down}
	tell process "Google Chrome"
		click (first button of first window whose title is "clear browsing data")
	end tell
end tell

Thanks