I need to perform automatic installation extension in Safari.
Now I have this part of code:
property extension_list : {"safariextz"}
on adding folder items to this_folder after receiving these_items
try
tell application "Finder"
repeat with i from 1 to (number of items in these_items)
set this_item to item i of these_items
set item_extension to name extension of this_item
if item_extension = "safariextz" then
tell application "Safari" to open this_item
delete this_item
end if
end repeat
end tell
on error errmsg
display dialog errmsg buttons {"OK"} default button 1
end try
end adding folder items to
This works, file is running after downloading.
But I cannot press button Install for starting installation extension.
I tried something like that
tell application "System Events"
tell process "Safari"
click the button "Install"
end tell
end tell
But this doesn't help.
Cloud you please assist to me with completing script for extension installation?
You must specify a window like this : click button 1 of window 1
open an "safariextz" file in Safari blocks the script, you must use ignoring application responses
The script must check that the dialog is displayed
on adding folder items to this_folder after receiving these_items
repeat with this_item in these_items
if (this_item as string) ends with ".safariextz" then
ignoring application responses
tell application "Safari" to open this_item
end ignoring
tell application "System Events"
tell process "Safari"
set frontmost to true
repeat until (exists window 1) and subrole of window 1 is "AXDialog" -- wait until the dialog is displayed.
delay 1
end repeat
click button 1 of front window -- install
end tell
end tell
end if
end repeat
end adding folder items to
Updated : as ignoring application responses doesn't work for you, try this
on adding folder items to this_folder after receiving these_items
repeat with this_item in these_items
if (this_item as string) ends with ".safariextz" then
tell application "Finder" to open this_item
For Safari 9, the button's context changed. Here's the script I figured out to get it back working. (This is only to show the order of commands and how to click the button.)
tell application "Safari" to activate
delay 2
tell application "System Events"
tell application process "Safari"
set frontmost to true
tell application "Safari" to open location "/path/to/SafariDriver.safariextz"
delay 2
click button 1 of sheet 1 of window 1
end tell
end tell
tell application "Safari" to quit
Related
I need a little applescript to open a password-protected pdf.
I can't figure out how to access the password text field.
The code I've got :
set elPdf to ("Path:to:my:file.pdf")
activate application "Preview"
tell application "Preview"
open elPdf
delay 1
tell application "System Events"
set value of text field 1 to "password"
keystroke return
end tell
end tell
Applescript is not finding the text/password field, even when I add "sheet 1" and "window 1"
How to I access the password field of a preview.app pdf with applescript?
I'd try to access password input via menu bar:
set myFolder to path to desktop as string
set myFile to myFolder & "trial.pdf"
tell application "Preview"
open myFile
activate
end tell
tell application "System Events"
tell process "Preview"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item 13
keystroke "34ue8XD5mM"
keystroke return
end tell
end tell
end tell
end tell
end tell
I have created a droplet that reads a textfile and gives the content to clipboard:
on open theFile
open for access theFile
set fileContents to (read theFile)
close access theFile
return fileContents
set the clipboard to fileContents
end open
But i am looking for some code to take this contents from clipboard
and insert it into the current field of the frontmost window of safari.
For this purpose i found some code used in an automator action that
simulates somehow the keystrokes of cmd+v:
on run {input, parameters}
tell application "Safari"
activate
tell application "System Events"
keystroke "v" using command down
end tell
return input
end tell
end run
My problem is how to put these two things together.
At the end the droplet should work this way:
drop textfile on droplet
insert content of textfile in active field of frontmost safari window.
thanks for help
This should get the job done for you.
I had the code keystroke a variable so you do not have to mess around with the clipboard and risk accidentally entering the wrong data.
on open the_file
set the_file_Contents to (read the_file)
tell application "Safari"
activate
tell application "System Events"
keystroke the_file_Contents
end tell
end tell
end open
If you wanted the code to use the clipboard still (more efficient for large text files), the code would look like this.
on open the_file
set the clipboard to (read the_file)
tell application "Safari"
activate
tell application "System Events"
keystroke "v" using command down
end tell
end tell
end open
I am trying to trap mouse click events in Safari with Applescript. My Applescript does what it needs to do, but I want to terminate if the user clicks on the document in Safari. I would like to set up an On_Click event in Applescript that would fire if the user clicks in the Safari document.
I do not know how to "trap" a mouse event with applescript. You'd have to use objective-c and the cocoa APIs for that.
However you might do it another way. Here's a quick example. Save this as a stay-open applescript application. When you run it the Safari window will scroll. To pause the scrolling just click the dock icon of the applescript. If you click the dock icon again then the scrolling will start again and vice versa. You'll notice that every time you click the dock icon the "on reopen" handler is executed which toggles the shouldScroll variable between true and false.
Anyway, I hope this gives you an idea for making your own script work. Remember you can quit the stay-open applescript by right-clicking on its dock icon and choosing quit. Good luck.
property shouldScroll : missing value
property theCounter : missing value
property counterMaxValue : missing value
on run
tell application "Safari" to activate
set shouldScroll to true
set theCounter to 0
set counterMaxValue to 2000
end run
on reopen
tell application "Safari" to activate
set shouldScroll to not shouldScroll
end reopen
on idle
if shouldScroll then
if theCounter is greater than counterMaxValue then set theCounter to 0
tell application "Safari" to tell document 1
do JavaScript "window.scroll (0," & (theCounter as text) & ")"
end tell
set theCounter to theCounter + 20
end if
return 0.1
end idle
You might exit the script when the focused window becomes a normal browser window, by for example testing if the frontmost window has a full screen button:
tell application "System Events" to tell process "Safari"
repeat until exists value of attribute "AXFullScreenButton" of window 1
--do something
delay 1
end repeat
end tell
Or if the script is supposed to stop when Safari becomes the frontmost application:
repeat until frontmost of application "Safari"
--do something
delay 1
end repeat
with
tell application "Safari"
set winlist to every window
repeat with win in winlist
set tablist to every tab in win
repeat with t in tablist
name of t as string
end repeat
end repeat
end tell
I can get the name of safari tab
how I can close a tab with a specific name ?
Here is another approach:
tell application "Safari"
set winlist to count of every window
repeat with i from 1 to winlist
close (every tab of window i whose name = "Google")
end repeat
end tell
tell application "Safari"
repeat with t in tabs of windows
tell t
if name starts with "autom" then close
end tell
end repeat
end tell
tell application "Safari" to close documents where name starts with "autom" would close all windows that contain tabs that start with autom.
It doesn't work for me 2
Neither of them work
The strange thing is, it does work when the safari is not in fullscreen
I guess it is a bug in safari
I'm trying to automatically select a menu item in iTunes using applescript. However, every time that I run this script I get an error message that says "expected end of line but found number, and points me to "scrollarea 1". I'm using Apple's UIElement inspector to get the names of the GUI elements in iTunes. Any help would be greatly appreciated.
Here's what I have so far:
tell application "iTunes"
activate
delay 10
tell application "System Events"
key code 53
tell outline 1 of scrollarea 1 of window 1
click menu 1
end tell
end tell
end tell
Well, I have it clicking what I need it to be clicking. The only problem now is that it's not actually clicking it, it's just returning the AXValue. I need it to actually click the item in iTunes itself.
activate application "iTunes"
tell application "System Events"
tell process "iTunes"
select row 15 of outline 1 of scroll area 2 of window "iTunes"
end tell
end tell