4.6 C
United States of America
Thursday, January 2, 2025

macos – Not in a position to clear Historical past in Safari utilizing AppleScript in OS X El Capitan


In OS X El Capitan, when clicking Clear Historical past… on the Historical past menu, it causes Clear Historical past to look both as a modal Dialog Field or as a targeted Sheet on a window, as illustrated within the photos on the backside of this reply, and the AppleScript code under handles it in both case situation.

The code is written with the idea it seems as a Dialog Field and if it fails to course of as a Dialog Field, then the on error handler processes it as a Sheet.

This code, straight under, primarily replicates what your code did in OS X Yosemite, though adjusted to be used in OS X El Capitan, sans the delay command which you’ll add if you need.


inform utility "Safari" to activate
inform utility "System Occasions"    
    click on menu merchandise "Clear Historical past…" of menu 1 of menu bar merchandise "Historical past" of menu bar 1 of course of "Safari"    
    attempt        
        click on button "Clear Historical past" of entrance window of course of "Safari"        
    on error
        attempt
            click on button "Clear Historical past" of sheet 1 of window 1 of course of "Safari"            
        finish attempt
    finish attempt
finish inform

To work together with the checklist on the Clear pop up button, for a way a lot of the Historical past to clear, the next code instance tackle it.

As a result of it might seem two alternative ways, it sadly requires two separate units of comparable code and each sections of code surrounding the “Clear …” checklist have to be manually maintained and in sync if/when utilizing that code phase.

Be aware: There are 10 traces of code commented out, preceded by --, pertaining to the “Clear …” checklist, 5 traces in every grouping of code. You’ll be able to change the present worth for one in all 4 decisions by uncommenting the click on pop up button 1 of window 1 of course of "Safari" and click on pop up button 1 of sheet 1 of window 1 of course of "Safari" traces of code, the one in every part, after which only one of the opposite 4 at a time, the same one in every part. This implies solely 4 traces complete are to be uncommented, 2 in every part, 1 to click on the popup button and the opposite for a way a lot of the Historical past you need cleared. The feedback I’ve added, preceded by -- #, throughout the code ought to be self-explanatory.

inform utility "Safari"
    activate
finish inform

inform utility "System Occasions"

    click on menu merchandise "Clear Historical past…" of menu 1 of menu bar merchandise "Historical past" of menu bar 1 of course of "Safari"

    attempt
        -- # 
        -- # NOTE: Hold this block of commented out code in sync with the same block under!
        -- # 
        -- # If you wish to change the worth of the "Clear ..." checklist, then uncomment the road of code straight under this remark.
        -- # 
        -- click on pop up button 1 of window 1 of course of "Safari"
        -- #     
        -- # When you've uncommented the road of code straight above this remark, then uncomment only one of the 4 traces of code under.
        -- # 
        -- click on menu merchandise "the final hour" of menu 1 of pop up button 1 of window 1 of course of "Safari"
        -- click on menu merchandise "at the moment" of menu 1 of pop up button 1 of window 1 of course of "Safari"
        -- click on menu merchandise "at the moment and yesterday" of menu 1 of pop up button 1 of window 1 of course of "Safari"
        -- click on menu merchandise "all historical past" of menu 1 of pop up button 1 of window 1 of course of "Safari"
        -- # 

        click on button "Clear Historical past" of entrance window of course of "Safari"

    on error
        attempt
            -- # 
            -- # NOTE: Hold this block of commented out code in sync with the same block above!
            -- #     
            -- # If you wish to change the worth of the "Clear ..." checklist, then uncomment the road of code straight under this remark.
            -- # 
            -- click on pop up button 1 of sheet 1 of window 1 of course of "Safari"
            -- #     
            -- # When you've uncommented the road of code straight above this remark, then uncomment only one of the 4 traces of code under.
            -- # 
            -- click on menu merchandise "the final hour" of menu 1 of pop up button 1 of sheet 1 of window 1 of course of "Safari"
            -- click on menu merchandise "at the moment" of menu 1 of pop up button 1 of sheet 1 of window 1 of course of "Safari"
            -- click on menu merchandise "at the moment and yesterday" of menu 1 of pop up button 1 of sheet 1 of window 1 of course of "Safari"
            -- click on menu merchandise "all historical past" of menu 1 of pop up button 1 of sheet 1 of window 1 of course of "Safari"
            -- # 

            click on button "Clear Historical past" of sheet 1 of window 1 of course of "Safari"

        finish attempt
    finish attempt
finish inform

This as coded runs very quick, nonetheless, you’ll be able to insert some delay instructions, the place applicable, if you wish to see higher what’s taking place because the Historical past is being cleared.


Within the photos under, one with the crimson arrow is pointing at what the ten traces of code commented out, preceded by --, pertaining to the “Clear …” checklist is about. To vary e.g., “the final hour” to one of many different values, that is the place you uncomment the suitable commented traces of code.

As a Sheet:
enter image description here

As a Dialog Field:

enter image description here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles