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
Related
Image of my accessibility inspector
I am writing a script that will run a microsoft office installation DMG and click continue and so on and on until the program is installed. I have been successful in navigating the buttons I need to press until I reached the Agree button. Accessibility Inspector says " (sheet) [NSPanel]" when I click on this button. How can I refer to this object? is it possible at all?
tell application "Finder"
set myFolder to container of (path to me) as alias
end tell
tell application "Finder"
open document file "Microsoft_Office_16.16.19021001_Installer.pkg" of myFolder
end tell
if application "Installer" is running then
tell application "Installer"
activate
end tell
tell application "System Events"
tell process "Installer"
click button "Continue" of window "Install Microsoft Office for Mac"
click button "Continue" of window "Install Microsoft Office for Mac"
click button "Agree" outline "" of window "Install Microsoft Office for Mac"
end tell
end tell
end if
Image of my accessibility inspector
Attempting to create automation to open a Safari browser with multiple tabs and login to common websites I use each day. I've achieved opening the browser and adding new tabs with specific URL's and prompting user for username and password but am having difficulty with simply moving between the open tabs.
I have tried assigning an index, naming the "current tab", using a title, etc. nothing seems to work... see sample below...
--Prompt user for login information
set GEmail to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
set GPassword to text returned of (display dialog "Enter Password" with title "Gmail" default answer "")
--Activate Safari and open new tab with URL
tell application "Safari"
activate
make new document with properties {URL:"https://gmail.com"}
delay 3
tell application "System Events"
delay 2
keystroke tab
keystroke GEmail
delay 2
keystroke tab
keystroke GPassword
keystroke return
end tell
--Create new tab pointing to Google > this does not actually open the new tab
set the URL of (make new tab in window 1) to "http://www.google.com"
end tell
I’ve tried multiple things but still cannot seem to actually move between the tabs and will eventually need to add several more tabs which I will need to toggle between.
To create a new tab, while setting focus to it, at a given URL use, e.g.:
tell application "Safari" to ¬
tell front window to ¬
set current tab to ¬
(make new tab with properties {URL:"http://www.google.com"})
I have culled together an applescript with great help from #chuck and other board posts to effectively batch print a list of files exported from filemaker containers to a folder called "print" on my desktop.
The problem I'm running into now is some of those container exports are not PDF (its a mix of Jpg, PNG, Tif and PDF) and will not open using acrobat (using preview for the PDF or any other PDF viewer is out of the question for a myriad of reasons)... This problem is effectively shutting down the work flow because of error messages from acrobat that must be manually clicked off before the script will proceed to the next file.
My question is can applescript be commanded to determine the file type first and choose a different program to open the document with and trigger the print command and close window before moving onto the next document in the sequence.
(i.e. if .pdf then use acrobat print close window, if not use preview to open file, print close window, repeat until all files have been printed.)
Below is my current working code.(FYI) This script is running within a filemaker script that is creating the "Print" folder on the desktop and exporting the container fields to the folder.
`set myFolder to (path to desktop folder as text) & "Print:"
set myfiles to list folder myFolder without invisibles
repeat with myfile in myfiles
set mycurrentfile to ((myFolder as string) & (myfile as string)) as string
batchprint(mycurrentfile)
end repeat
on batchprint(mycurrentfile)
tell application "Adobe Acrobat Pro"
activate -- bring up acrobat
open alias mycurrentfile -- acrobat opens that new file
tell application "System Events"
tell process "Acrobat"
click menu item "Print..." of menu 1 of menu bar item "File" of menu bar 1
click button "Print" of window "Print"
tell application "System Events"
tell process "Acrobat"
click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
end tell
end tell
end tell
tell application "Finder" -- to move the printed file out
set x to ((path to desktop folder as text) & "Printed PDFs:")
if alias x exists then
beep
else
make new folder at the desktop with properties {name:"Printed PDFs"}
end if
move alias mycurrentfile to folder "Printed PDFs"
end tell
end batchprint`
Use Finder to test for the file type and the extension, then use your Acrobat tell block if it's a pdf, and use Preview or whatever if it is not.
Here's the code structure for that:
tell application "Finder" to set {fType, nExt} to ({file type, name extension} of file mycurrentfile)
if (fType is "PDF ") or (nExt is "pdf") then
-- Open mycurrentfile with Acrobat
tell application "Adobe Acrobat Pro"
...
else
-- Open mycurrentfile with something else
tell application "Preview"
...
end if
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
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