Re: Script to clear Safari?
Re: Script to clear Safari?
- Subject: Re: Script to clear Safari?
- From: "Stockly, Ed" <email@hidden>
- Date: Mon, 22 Feb 2016 18:20:13 +0000
- Thread-topic: Script to clear Safari?
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
On 2/22/16, 9:14 AM,
"applescript-users-bounces+ed.stockly=email@hidden on
behalf of email@hidden"
<applescript-users-bounces+ed.stockly=email@hidden on
behalf of email@hidden> wrote:
>AppleScript Users,
>
>I am looking for help to create an AppleScript which I can save in
>Automator as an application. I would like the AppleScript to do two
>things:
>1) If any Safari windows & tabs are open, close them all;
>2) Clear the cookies, cache, and history.
>
>I've cobbled together a script that throws an error, but does accomplish
>the clear history task. I tried Automator's follow my action/record
>function, but the result won't work if the Safari window isn't in the
>exact same place on the screen.
>
>on run {input, parameters}
> tell application "System Events"
> tell process "Safari"
> set frontmost to true
> click menu item "Clear History
" of menu 1 of menu bar item
>"Safari" of menu bar 1
> delay 1
> click button "Clear History" of window 1
> end tell
> end tell
> return input
>end run
>
>Anyone have a suggestion on how to script Safari to "close windows" and
>"clear history"?
>
>Thanks,
>Douglas Bat
>
>
> _______________________________________________
>Do not post admin requests to the list. They will be ignored.
>AppleScript-Users mailing list (email@hidden)
>Help/Unsubscribe/Update your Subscription:
>imes.com
>Archives: http://lists.apple.com/archives/applescript-users
>
>This email sent to email@hidden
_______________________________________________
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