PDA

View Full Version : Making Compress Pictures Dialogue Box Selections in Mac



Delamayne
10-01-2020, 07:24 AM
Hi,

I have code that in PC:
1. automatically initiates the 'compress pictures' dialogue box
2. changes default selections in that dialogue box
3. runs compress pictures

Step 1 works in mac, steps 2 and 3 use SendKeys, which needs another solution.

I saw another post that provided in great detail how you can use MacScript in VBA to replicate SendKeys functionality in Mac. I think I can figure that part out.

My Question is: Is it even possible to use hotkeys/the keyboard to navigate the 'compress pictures' dialogue box in Mac PPT, and change default selections?
Other than hitting enter to run it (which DOES work), any attempt to tab through, move up and down, or otherwise select/change one of the radio buttons or dropdowns has failed. That's when attempting to change these settings manually (with just the keyboard). If I can't navigate and change selections in the dialogue box using the keyboard in Mac, then it doesn't matter whether or not there is a SendKeys workaround.


The Compress Dialogue boxes for PC and Mac PPT office 360 are pictured below.
In Mac, I would need to use keyboard to navigate and specify selections for each of the indicated sections (dropdown list, checkboxes, radio buttons)


compressorstart:
opic.Select 'From earlier part of the code - ensures that some shape that is an mso picture (or placeholder) is selected prior to running
CommandBars.ExecuteMso ("PicturesCompress")
SendKeys "%{u}" 'chooses "Use Default Resolution" radio button
SendKeys "a-" 'force unchecks "Apply Only To This Picture" checkbox
SendKeys "{ENTER}" 'Run it
End Sub

27253

Delamayne
10-05-2020, 03:04 PM
I have resolved part of this. It requires a mac user to one-time go to System Preferences >> Keyboard >> Shortcuts >> and Check the "Use Keyboard Navigation" box to enable tab, arrow scrolling in dialog boxes.

There is an issue. If the Compress Pictures dialog box is already open, and this code is then run from Apple Script Editor, it works. However, if it is ALL done in vba (open the compress pictures dialog box via CommandBars.ExecuteMso ("PicturesCompress"), then run this macscript, the macscript will not execute until the dialog box has been closed.

If there is a solution, it is appending this code to open the compress pictures dialog box using macscript, instead of commandbars.executemso("PicturesCompress"). Still investigating, will update if I figure it out.

If anyone has macscript that succeafully interacts with/clicks on things from the ribbon, any help would still be appreciated!

MacScript version. (this code would run after some arbitrary picture in the deck was clicked on. Does NOT work because the macscript will not execute until the dialog box is closed.

The raw apple script is below that. If you run that from script editor after opening the compress pictures dialog box, it works.




Dim MacCompressionExec As String
MacCompressionExec = "tell application ""System Events""" & vbNewLine & _
"tell process ""Microsoft PowerPoint""" & vbNewLine & _
"set frontmost to true" & vbNewLine & _
"key code 125 #Down Arrow - Open Picture Qualiy Dropdown " & vbNewLine & _
"key code 14 #E - Email, in case Print (P) and Use Original Quality (U) Are Unavailable" & vbNewLine & _
"delay 1 #Can't select again for half a sec or so" & vbNewLine & _
"key code 35 #P - Print, in case Use Original Quality is Unavailable" & vbNewLine & _
"delay 1" & vbNewLine & _
"key code 32 #U - Use Original Quality" & vbNewLine & _
"key code 36 #Enter - Select option from Picture Quality dropdown" & vbNewLine & _
"key code 48 #tab" & vbNewLine & _
"key code 48 #tab - tab twice to radio buttons" & vbNewLine & _
"delay 1" & vbNewLine & _
"key code 126 #Up Arrow - All Pictures is always the top option, does not cycle back once at top" & vbNewLine & _
"delay 1" & vbNewLine & _
"#key code 36 #Enter to run" & vbNewLine & _
"#return ""Done""" & vbNewLine & _
"end tell" & vbNewLine & _
"end tell"
CommandBars.ExecuteMso ("PicturesCompress")
MacScript (MacCompressionExec) 'Doesn't work because you have to close dialog box before it will run••••ˇˇˇˇ


'AppleScript

tell application "System Events"
tell process "Microsoft PowerPoint"
set frontmost to true
key code 125 #Down Arrow - Open Picture Qualiy Dropdown
key code 14 #E - Email, in case Print (P) and Use Original Quality (U) Are Unavailable
delay 1 #Can't select again for half a sec or so
key code 35 #P - Print, in case Use Original Quality is Unavailable
delay 1
key code 32 #U - Use Original Quality
key code 36 #Enter - Select option from Picture Quality dropdown
key code 48 #tab
key code 48 #tab - tab twice to radio buttons
delay 1
key code 126 #Up Arrow - 'All Pictures' is always the top option, does not cycle back once at top
delay 1
key code 36 #Enter to run
end tell
#end tell
end tell

paespi
11-13-2023, 05:28 AM
Finally, I made it work using a combination of both AppleScripts and VBA Macros.

So, basically, I started the macro execution from AppleScript and the macros does its thing until it reaches the Compress Images dialog.
The macro is saved on a centrally macro-enabled file that I left open all the time while needing this.

Later, I hit ENTER / RETURN using AppleScript so that the macro can continue.

This is the AppleScript:




on compactImages(ppt)
tell application "Microsoft PowerPoint"
open ppt
activate
repeat until frontmost
delay 0.1
end repeat
end tell

tell application "System Events"
click menu item "Macros..." of menu "Macro" of menu item "Macro" of menu "Tools" of menu bar item "Tools" of menu bar 1 of application process "PowerPoint"
delay 0.1
-- choose workbook with Macros
tell pop up button 1 of window 1 of application process "PowerPoint"
click
click menu item 2 of menu 1
end tell
delay 0.03
-- choose the right macro
tell text field 1 of window 1 of application process "PowerPoint"
set value to "OpenDialogCompressPicturesAndSaveAndClose"
end tell
delay 0.5
-- run it
click button "Run" of window 1 of application process "PowerPoint"




-- Compress Pictures dialog
delay 0.5
-- choose> "On-screen (150 ppi)"
tell pop up button 1 of group 1 of window 1 of application process "PowerPoint"
click
click menu item 4 of menu 1
end tell
-- choose "All pictures in this file"
click radio button 1 of radio group 1 of group 1 of window 1 of application process "PowerPoint"
delay 0.03
-- click OK to compress all images
keystroke return
end tell
end compactImages




set ppts to (do shell script "ls '/<<YOUR-PATH>>/'*.pptx")'s paragraphs


if ppts is {} then return


repeat with ppt in ppts
compactImages(ppt)
log ppt
end repeat






This is the VBA macro:



Sub OpenDialogCompressPicturesAndSaveAndClose()
Dim shp As Shape
Dim sld As Slide
Dim atLeastOneImageSelected As Boolean
Dim ppt As Presentation

atLeastOneImageSelected = False
For Each sld In ActivePresentation.Slides
sld.Select
For Each shp In sld.Shapes
If shp.Type = msoPicture Then
shp.Select
atLeastOneImageSelected = True
Exit For
ElseIf shp.Type = msoPlaceholder Then
If shp.PlaceholderFormat.ContainedType = msoPicture Then
shp.Select
atLeastOneImageSelected = True
Exit For
End If
End If
Next shp

If atLeastOneImageSelected Then Exit For
Next sld


If atLeastOneImageSelected Then
CommandBars.ExecuteMso "PicturesCompress"
End If


'Now I want to save the presentation and close it without closing other open PowerPoint files
With Application.ActivePresentation
If Not .Saved And .Path <> "" Then .Save
End With


'If PowerPoint.Application.Version >= 9 Then
' PowerPoint.Application.Visible = msoTrue
'End If
PowerPoint.ActivePresentation.Close
End Sub