2

I need to open my OS X application when any powerpoint presentation opens. I got VBA call back when powerpoint open (Auto_Open()). But I need a call back for each presentation open.

In windows we can open each presentation in separate powerpoint app (difference instance). In Mac , Powerpoint app will open once and all presentation will open under same powerpoint application (Powerpoint 2016- Mac version) .

I need a call back when each presentation file open and I need to do run code snippets in my cocoa application.

Sivaprasad Km
  • 712
  • 4
  • 15
  • You may be able to string something together using `fswatch` (install with `homebrew`) to recursively watch user folders for file opens of PDF files. Or maybe something with `sudo opensnoop -n PowerPoint` or somesuch. – Mark Setchell Oct 17 '16 at 09:25
  • "In windows we can open each presentation in separate powerpoint app (difference instance)" Actually no, you can't. Recent versions allow you to open multiple files in individual windows, but there's only one instance of the app. Your app could possibly query PPT periodically for the Presentations.Count property, possibly maintain an array/list of the names of each open presentation to check against. In Windows, PPT can trap an event thrown when presentations open but as far as I know, this isn't supported in Mac PPT. – Steve Rindsberg Oct 17 '16 at 13:08
  • @SteveRindsberg: In windows , Its new info to me. Thank you for the update and in Mac PPT supporting only few events. There is one event in ppt Application.PresentationOpen Event, I think it will give call back when each presentation opens. But This event is not supporting in Mac version. Is there any other way to identify when presentation open ? Anything like mac activity monitoring or something ? – Sivaprasad Km Oct 17 '16 at 14:22
  • @SivaprasadKm Not that I know of, but I don't know much about Mac other than what happens in VBA. There might be some way of doing this with Applescript or the like. Ah. I see pbell has given you a possible example. – Steve Rindsberg Oct 18 '16 at 15:53

1 Answers1

0

An idea of possible work around is to loop checking the presentations opened, and compare it with presentations already open before.

First, when this script starts running, it checks if PowerPoint is running (-> if not then quit). If PP runs, then the script records the number of open presentations.

Then script goes through a loop : in this example, it repeats 100 times (just for my test, but it should be repeat for ever !). For each iteration, it looks for list of PP presentation and compares with list before: if a presentation is not in previous list, then it is new, jut open !

The script also stops when you quit PowerPoint showing an alert (bloc try).

tell application "System Events" to set PP_Running to exists (processes where name is "Microsoft PowerPoint")
if not PP_Running then return -- Power point is not launched !
tell application "Microsoft PowerPoint" to set Old_list to name of every presentation -- get initial list of open presentations

repeat with I from 1 to 100 -- for test, but it should be repeat with no limit

try
    tell application "Microsoft PowerPoint" to set New_list to name of every presentation
on error
    display alert "PowerPoint no longer launched"
    return -- quit the loop
end try
repeat with aDoc in New_list
    if not (Old_list contains aDoc) then -- new document has been opened !!
        set Old_list to New_list
        log "Open new document = " & aDoc -- do what ever you need to do !!
    end if
end repeat
delay 0.5
set I to I + 1
end repeat

Tested on El Capitain / PP 2011 : but I think there is nothing changed from PP 2011 to PP 2016 in the 'name of every presentation'.

pbell
  • 2,965
  • 1
  • 16
  • 13