I am looking for some help on correcting this error:

error "System Events got an error: Can’t get menu item \"Clear History...\" of menu \"Safari\" of menu bar 1 of process \"Safari\"." number -1728 from menu item "Clear History..." of menu "Safari" of menu bar 1 of process "Safari"

My code is:

tell application "Safari"
    if not (exists document 1) then
        make new document at front
    end if
end tell
delay 1
tell application "System Events"
    keystroke "e" using {option down, command down}
    tell process "Safari"
        tell menu bar 1
            tell menu "Safari"
                tell menu item "Clear History..."
                    every UI element
                end tell
            end tell
        end tell
        tell window 1
            tell sheet 1
                tell button "Clear History"
                end tell
            end tell
        end tell
        tell menu bar 1
            tell menu bar item "Develop"
                tell menu 1
                    click menu item "Empty Caches"
                end tell
            end tell
        end tell
    end tell
end tell
  • I'm far from being an expert on this, but I'm pretty sure you need to be looking at AXMenuItems to be able to accurately hit a specific menu command by Applescript, as I did in this Answer - apple.stackexchange.com/a/209219/85275 - More good luck than good management got me there, but it might be useful to you.
    – Tetsujin
    Dec 4, 2015 at 11:17
  • Will that be applicable since this is not a Check/Uncheck option? Dec 4, 2015 at 11:25
  • That, I'm not absolutely certain on - but I think you need that structure to find the menu option in the first place. The long list of "of menu "x" of menu item 1 of …" etc seems crucial, though - & it's one part I really do not fully comprehend as to how it is structured. My Googling took me far & wide whilst trying to work out that answer.
    – Tetsujin
    Dec 4, 2015 at 11:34
  • Just to clarify: You want to click Clear History and Empty Caches right?
    – Arc676
    Dec 4, 2015 at 11:50
  • Yes, correct. I am basically wanting to reset safari. Which is emptying cache and clearing history Dec 4, 2015 at 11:58

2 Answers 2


I think you need to make the menu item "Clear History and Website Data…", not "Clear History and Website Data..." (a single ellipses character: "…" vs. three periods: "..."

I didn't test the whole script, but this change brought the menu item up in Safari for me via AppleScript.


This was nagging me and I found this post in my search.

Definitely in my case I needed an ellipsis character (…) instead of three periods (...) after the menu item I was trying to have AppleScript click.

Copy/paste the ellipsis in this message or the answer above.

NOTE: the ellipsis character LOOKS (nearly?) identical to three periods without spaces when viewed on this web page, so it is not immediately visible that there is a difference in the examples below just by looking at them, but if you try to copy, you'll see that one has a single character after the word "History" and the other has three characters (all periods).


tell menu item "Clear History..."

but YES:

tell menu item "Clear History…"

  • The other answer already stated the need for... a single ellipses character: "…" vs. three periods: "..." Nov 18, 2021 at 23:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .