intercepting open and close

I’d like to automatically run a script (either an AS or shell script) immediately after a given application opens any document.

Is there a way to detect when any document is opened by a given application?

Similarly, I’d like to automatically run a script immediately after the document is closed.

Thoughts?

Thanks,
humanengr

Thoughts…

Missed that – thanks

Hello

you could write a script to use to open documents in your application, something like this:

Shamelessly stolen from Bill Cheesman:


set theApplication to choose application as alias
set theFile to choose file
tell application "Finder"
” do your own stuff here with the file
	open theFile using theApplication
end tell

You could similarily use a script to close the document (frontmost preferably)

Just look away from the triggering, but use something like quicksilver or fastscripts to overshadow the keys you use to open and close documents with, in that application.

Hi,

just in case … if you’re talking about InDesign → its got events on open, close etc. …

@McUsr: That’s handy (thanks for the shamelessness). But I’m hoping for something that will work automatically when opening from the Finder, as explained below.

@Hans-Gerd Classen: The app is Skim (my default pdf reader/annotator). I’m looking for a way, when opening a file by double-clicking in Finder to automatically and immediately (in Skim parlance) “unembed” annotations.

Skim offers two ways to unembed: 1) File:Convert (also AS-able) and 2) via the skimpdf command line tool (/Applications/Skim.app/Contents/SharedSupport/skimpdf unembed ) for a file that is not open.

So, as it stands, when I double-click to open a file, to unembed any embedded notes, I have to either

  1. File:Convert,

  2. call an AS such as

which I call via a Fastscript shortcut.

or

  1. before the file opens, use skimpdf either directly in shell or indirectly from an AS.

But I don’t see how to invoke any of these automatically in response to a double-click to open a file.

Hello. :smiley:

Actually, there is a way to intercept it, if you are willing…

You install RCDefaultApp preference pane http://www.rubicode.com/Software/RCDefaultApp/, then you write a little background application, that has an on open handler, that does the stuff for you, or tells Skim to do it, and anyways, passes the file over to Skim, done, or with instructions.

The whole process in concept; is described here: http://hints.macworld.com/article.php?story=20091013114424722

Of course for you it will be about the on open handler, and not the on open location hander.

I hope this helps!

Thanks for the pointer. :slight_smile:

Will report back.