Keystroke "[" using command down in Safari?

Can someone remind me why this wouldn’t work? Compiles fine, just gets a beep. Seems I have used it in the past.


tell application "System Events"
	tell process "safari"
		keystroke "[" using command down
	end tell
end tell

Should I use the Delete key instead? If so what’s the code for that key?

Appreciated.

this works for me…

tell application "Safari" to activate
tell application "System Events" to tell process "Safari" to keystroke "[" using {command down}
tell application "Safari" to activate
tell application "System Events" to tell process "Safari" to keystroke (ASCII character 8) -- delete key

Tom

Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

Hi Johnny
You can also do it with the “set frontmost to true” option

tell application "System Events"
	tell process "Safari"
		set frontmost to true
		keystroke "[" using command down
	end tell
end tell

Thanks for confirming that. Now it works. Not sure what my error was.

The error was that the script did not make Safari frontmost (somehow) before it sent a GUI command to it.

Yep. I forgot that part.

Or maybe there was no page to go back to - that would have really been a “duh” moment if I had realized it.