• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Script to clear Safari?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script to clear Safari?


  • Subject: Re: Script to clear Safari?
  • From: Steve Mills <email@hidden>
  • Date: Mon, 22 Feb 2016 19:04:42 +0000 (GMT)

On Feb 22, 2016, at 12:21 PM, "Stockly, Ed" <email@hidden> wrote:

Try something like this. When clearing history, it will clear the last
level the user selected.

The choices are something like "Last Hour", "Today", "Today and Yesterday"
and "All History"

You could do a line to set that to whichever option you prefer in your
script.


—————

tell application "Safari" to activate
CloseSafariWindows()
resetSafari()
on resetSafari()
     try
         tell application "Safari"
                 activate
                       repeat with x from 1 to the count of windows
                               close window 1
                   end repeat
           end tell
               tell application "System Events"
                       tell process "Safari"
                         click menu item "Clear History and Website Data…" of menu 1 of menu
bar item "Safari" of menu bar 1
                           click button "Clear History" of window 1
                       end tell
               end tell
               
       end try
end resetSafari

on CloseSafariWindows()
     try
         tell application "Safari" to set windowIDs to the id of every window
               repeat with thisId in windowIDs
             tell application "Safari" to set myId to thisId as integer
                   tell application "Safari" to set myWindow to myWindow as integer
                       if (thisId as integer) ≠ (myWindow as integer) then
                     tell application "Safari" to close (window 1 whose id = thisId)
             end if
           end repeat
           if myBounds ≠ {} then
                 tell application "Safari" to set bounds of window 1 to myBounds
     end if
   on error errText
               --my ClearRandomErrors()
       end try
end CloseSafariWindows

myBounds is never initialized.

I've use a different method of operating only on the non-missing windows:

set n to name of wind


--Some windows return a non-value, so n will be undefined. I hate that part of AppleScript:

try

   n

on error

   set n to ""

end try


if n is not "" then

   do stuff to the window

end if


Sent from iCloud's ridiculous UI, so, sorry about the formatting

 
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Script to clear Safari?
  • Next by Date: Re: Script to clear Safari?
  • Previous by thread: Re: Script to clear Safari?
  • Next by thread: Re: Script to clear Safari?
  • Index(es):
    • Date
    • Thread