[texworks] SCRIPTING: get current poppler page number

Paul A Norman paul.a.norman at gmail.com
Thu Oct 21 10:37:56 CEST 2010


Thank you Bruno,

That helped set me on a good search angle. Googled: tell application
"Adobe Acrobat Reader"

(Every time I see something of Apple I am amazed at how elegant it is
- the syntex of that script language -below- is amazing)

AMong other things I found this:

http://macosx-tex.576846.n2.nabble.com/TeXShop-Engine-to-use-Acrobat-as-previewer-td5087826.html

" ... Not all is lost as one can implement most of the functionality
using System Events, but the preview will always open on page 1 ..."

Which seems to say it all.

Also a pdf on the adobe acrobat(8) site:
http://www.adobe.com/devnet/acrobat/pdfs/reader_overview.pdf

Page 27

Apple events
On Mac OS, you may use Apple events and AppleScript. Adobe Reader
supports only the following required Apple events:
●open
●print
●quit
●run

Now unless ther is a way we can pass the options like page=NN to the
open "Apple event", this may be a dead end, does Ramón's  script below
look like this can be done please? (We probably don't want all the
screen placement stuff )

Paul

---------
Part of --   http://macosx-tex.576846.n2.nabble.com/TeXShop-Engine-to-use-Acrobat-as-previewer-td5087826.html

Aloha,

Alas the engine I posted only works fully for Adobe Acrobat Pro and
not Adobe Reader, since although they have the same applescript
dictionary Acrobat Reader does not have many of the commands
implemented.

Not all is lost as one can implement most of the functionality using
System Events, but the preview will always open on page 1. Moreover,
the Acrobat engine will set the preview position to the TeXShop
default on its first run, but once there is a preview open it will
position subsequent previews in the place the user chooses (until she
closes it). The Reader engine always opens the preview in the same
place, as defined by TeXShop.

Finally, you must open System Preferences and check Enable Access for
Assistive Devices in the Universal Access preference pane, for this
engine to work.

Enjoy! (but not as much)

Ramón

---------------------------code starts after this
line--------------------------
#!/bin/bash

PATH="$PATH:/usr/texbin:/usr/local/bin"

name=$(basename "$1" .tex)
basefname="`pwd`/${name}"

# Change this line to whatever typesetting command you like that produces PDFs.
# pdflatex --file-line-error --shell-escape --synctex=1 "$1"
# comment the line above and uncomment the one below if you wish to use an
# installed TeXShop engine. Here we use pdflatexmk as an example.
~/Library/TeXShop/Engines/pdflatexmk.engine "$1"

# Get TeXShop's PDF window position
window=`defaults read TeXShop "NSWindow Frame PdfKitWindow"`
# replace every space run by a single space
window=`echo $window | sed 's/ +/ /g'`

x=`echo "$window" | cut -d ' ' -f 1`
y=`echo "$window" | cut -d ' ' -f 2`
width=`echo "$window" | cut -d ' ' -f 3`
height=`echo "$window" | cut -d ' ' -f 4`

# Close any preview that already exists (if any) and open the new one.
/usr/bin/osascript  <<END
activate application "Adobe Reader"
tell application "System Events"
        tell process "Adobe Reader"
                try
                        click button 1 of window "$name.pdf"
                end try
        end tell
end tell

set x to $x
set y to $y - 115
set h to $height + 115
set w to $width

tell application "Adobe Reader"
        open POSIX file "$basefname.pdf"
end tell

tell application "System Events"
        tell process "Adobe Reader"
                set position of window "$name.pdf" to {x, y}
                set size of window "$name.pdf" to {w, h}
        end tell
end tell

END

# We close the pdf window in TeXShop
close_window="tell application \"TeXShop\" to close (every window
whose name is \"$name.pdf\")"

/usr/bin/nohup /usr/bin/osascript  -e "$close_window" &



On 21 October 2010 20:13, Bruno Voisin <bvoisin at me.com> wrote:
> Le 21 oct. 2010 à 05:05, Paul A Norman a écrit :
>
>> P.S.
>> http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_API_AppleEvtObjects.105.1.html#1515777
>>
>> The adobe page for the Apple Events information, is virtually empty.
>>
>> On 21 October 2010 15:40, Paul A Norman <paul.a.norman at gmail.com> wrote:
>>>
>>
>>> APPLE MAC
>>>
>>>  "When opening a PDF document with an Apple Event on a Macintosh
>>> operating system,
>>>  you can optionally pass the PDF Open parameters."
>>>
>>> What does this mean to a Mac user please? - i.e. what is an "Apple Event"
>
> I'm only guessing here, having never done any scripting myself, but I think Apple Event in this sense relates to AppleScript, the Mac scripting language:
>
> http://en.wikipedia.org/wiki/AppleScript
> http://www.macosxautomation.com/applescript/learn.html
>
> Acrobat doesn't support AppleScript in itself, it seems to have built its scripting support around JavaScript:
>
> http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JavaScript_SectionPage.70.1.html
>
> However, it seems that JavaScript is used to execute scripts inside Acrobat, not to launch Acrobat. And you're quite right, whatever Adobe says about interapplication communication API relates to MS Visual Basic, not Apple Script, with the page on interapp communication
>
> http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JavaScript_SectionPage.70.1.html
>
> leading to the empty page you mentioned on Apple Events support.
>
> Two more things:
>
> - The extract you gave seems to imply that it's possible to call Acrobat through an AppleScript and pass on the PDF Open parameters from
>
> http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/pdf_creation_apis_and_specs/PDFOpenParameters.pdf
>
> inside the Apple Script. Googling for "applescript acrobat" returns
>
> http://dotclue.org/archives/002542.html
>
> which appears as an example of combining Acrobat and AppleScript.
>
> - Generally, and I realize this is a controversial topic, Adobe apps on the Mac are in my experience second thoughts, hasty ports, of Windows applications. They work like Windows apps, not Mac apps, and are very badly optimized, often using up 95% of the CPU with no particular reason, blocking the current app sometimes for minutes and not letting the user switch gracefully to other applications as apps normally do, and at times crashing. I've experienced this repeatedly over more than a decade with successive versions of Illustrator, Reader/Acrobat and Flash Player. Basically you use an Adobe app or plug-in on the Mac because you have to, not because you enjoy to.
>
> All this to say that that lack of OS X scripting support in Acrobat, if that is indeed the case, would not come out as a surprise.
>
> Bruno Voisin
>



More information about the texworks mailing list