apple scripting for Preview in Mojave
iMac (Retina 5K, 27-inch, Late 2015); Processor 4GHz Intel Core I7; Memory 16GB 1867 Mhz DDR3; Startup Disk iTB Fusion; MacOS Mojave (10.14)
I had previously had run an Apple Script on the Preview Application running OS 10.12. That script doesn't run on 10.14. In fact, when I open the Script Editor in the Utilities Folder and look for applications that it will work with Preview isn't listed. Are there plans to add Preview scripting features? I have a desperate need to use Preview to convert PDF files to JPEG files after opening the PDF file from the Print Directory.
I used the following Apple Script in OS 10.12.
-- Click the “File” menu.
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click menu bar item \"File\" of menu bar 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Export…
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click menu item 13 of menu 1 of menu bar item \"File\" of menu bar 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Press ⌘V
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "keystroke \"v\" using command down"
my doWithTimeout( uiScript, timeoutSeconds )
-- Make a selection from the popupbutton.
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click pop up button 1 of group 2 of sheet 1 of window 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- PDSC Picture Folder
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click menu item \"PDSC Picture Folder\" of menu 1 of pop up button 1 of group 2 of sheet 1 of window 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Make a selection from the popupbutton.
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click pop up button 1 of group 1 of sheet 1 of window 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- JPEG
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click menu item \"JPEG\" of menu 1 of pop up button 1 of group 1 of sheet 1 of window 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Click the “Save” button.
delay 0.15
set timeoutSeconds to 2.000000
set uiScript to "click UI Element \"Save\" of sheet 1 of window 1 of application process \"Preview\""
my doWithTimeout( uiScript, timeoutSeconds )
-- Press ⌘W
delay 0.5
set timeoutSeconds to 2.000000
set uiScript to "keystroke \"w\" using command down"
my doWithTimeout( uiScript, timeoutSeconds )
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
iMac, OS X Yosemite (10.10.2), I also have a MBP & Mac Mini