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