Not able to clear History using applescript in El Capitan OSX - applescript

I have been using below script to clear the safari history from selenium test in Yosemite OSX. I have upgraded the OS to El Capitan and now the script wont work.
Error returned : Can't get "Clear History" button
Any help on this please.
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
tell menu bar 1
tell menu bar item "History"
tell menu 1
click menu item "Clear History…"
end tell
end tell
end tell
delay 1 -- optional
click button "Clear History"
end tell
end tell

tell application "Safari" to activate
set frontmost to true
tell application "System Events"
tell process "Safari"
set frontmost to true
click menu item "Clear History…" of menu "History" of menu bar 1
delay 3
click button "Clear History" of sheet 1 of window 1
end tell
end tell
tell application "Safari" to quit

Related

Applescript to turn mirroring on and select iPad

I recently updated my mac to Monterey and my old applescript is not working anymore and I get this error: 'System Events got an error: Can’t get pop up button 1 of window 1 of process "System Preferences". Invalid index.'
I honestly have no idea which part should I change. Thank you in advance.
tell application "System Preferences"
set current pane to pane "com.apple.preference.displays"
activate
end tell
tell application "System Events"
tell process "System Preferences"
click pop up button 1 of window 1
click menu item 1 of menu 1 of pop up button 1 of window 1
end tell
end tell
tell application "System Preferences"
delay 10
quit
end tell
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
activate
end tell
tell application "System Events"
tell application process "System Preferences"
click pop up button "Add Display" of window "Displays"
click menu item 2 of menu 1 of pop up button "Add Display" of window "Displays"
end tell
end tell
tell application "System Preferences"
delay 5
quit
end tell

How to close Safari preference window using AppleScript?

I am using the below script to enable developer menu.
tell application "Safari"
tell application "System Events"
tell process "Safari"
click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
click button "Advanced" of toolbar 1 of window 1
click checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
-- delay 2
keystroke "w" using {command down} -- > not working
end tell
end tell
end tell
How to close the preference window? With keystroke "w" using {command down}, I am getting cannot The document cannot be closed while the script is running. error.
Also how to enable checkbox only if it is not enabled? Currently, if I run the script twice, it toggles.
Just click the first button of the first window and check the value of the checkbox
tell application "Safari"
tell application "System Events"
tell process "Safari"
click menu item "Preferences…" of menu 1 of menu bar item "Safari" of menu bar 1
click button "Advanced" of toolbar 1 of window 1
tell checkbox "Show Develop menu in menu bar" of group 1 of group 1 of window 1
if value is 0 then click it
end tell
click button 1 of window 1
end tell
end tell
end tell
This AppleScript code works for me using the latest version of macOS Mojave.
tell application "System Events"
tell application process "Safari"
set frontmost to true
end tell
keystroke "." using {command down}
end tell

Need applescript for clear cookie on MAC for Safari 8 browser

I need to perform below things using applescript.
Launch Safari,
click "Clear History and Website Data" on Safari menu bar,
click "Clear History" button,
close safari browser.
I have tried with below code:
tell application "Safari" to activate
tell application "System Events"
click menu item "Clear History and Website Data…" of menu "Safari" of menu bar item "Safari" of menu bar 1 of application process "Safari"
delay 1
click button "Clear History" of pop up "Safari"
quit
end tell
tell application "Safari" to activate
set frontmost to true
tell application "System Events"
tell process "Safari"
set frontmost to true
click menu item "Clear History…" of menu "History" of menu bar 1
delay 3
click button "Clear History" of sheet 1 of window 1
end tell
end tell
tell application "Safari" to quit

Verify a checkbox before clicking with Applescript

I'm facing an issue with one of my applescript.
I'm trying to create an applescript that check/uncheck the checkbox that call the password after the mac wake up or the screensaver stop in the mac security pannel.
I'm using this with proximity.app, with the idea that when i'm back home and my phone is in range, proximity.app remove the password, but when i'm out of range, it put the password back.
Well... I'm forced to do it using UI scripting, because of the new security policy in Mountain Lion.
So there is the code when out of range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
if not 1 then click checkbox 1
click menu item 6 of menu of pop up button 1
end tell
end tell
end tell
end tell
quit
end tell
and when in range :
tell application "System Preferences"
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
tell first window
tell first tab group
click radio button 1
click checkbox 1
end tell
end tell
end tell
end tell
quit
end tell
What i want to improve, is a way to first verify if the box is check or uncheck before checking or unchecking it.
Thanks for your help.
Just check the value of the checkbox.
0 = Uncheck, 1 = check
tell application "System Preferences" to ¬
reveal anchor "Advanced" of pane id "com.apple.preference.security"
tell application "System Events"
tell first tab group of first window of process "System Preferences"
tell checkbox 1 to if value is 0 then click -- checkbox was not checked.
end tell
end tell
quit application "System Preferences"

Dropdown in Monitor System Preferences

tell application "System Events"
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.displays"
set theWindows to windows
set win2 to item 2 of theWindows
tell win2
set index to 1
set visible to false
set visible to true
end tell
set value of combo box 1 to "90°"
end tell
end tell
I'm trying to change the Rotation of the External Screen via Applescript, but I do
not find out how to access this dropdown menu. Google seems to give me a lot about combo box and pop menu, but under Lion at least all this stuff doesn't work.
This worked for me on 10.8.
tell application "System Preferences"
reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
end tell
tell application "System Events" to tell process "System Preferences"
tell pop up button 1 of tab group 1 of window 1
click
click menu item 3 of menu 1
end tell
end tell

Resources