My setup is 2020 MacBook Pro M1 (Apple silicon), Big Sur 11.2.2, MacPorts, emacs-mac-app, AucTeX, and PDF Expert. I am trying to get C-c C-c (View) to open PDF Expert at the right page. I'm almost there, but my AppleScript wrapper for PDF Expert is not completing properly. The AppleScript wrapper, ~/bin/pdfe, is below. It is invoked as "pdfe filename page-number". It works fine from the command line, but does not seem to execute the "tell" portion when executed through Emacs (setq TeX-view-program-list '(("PDFExpert" "pdfe %o %(outpage)"))).

    use framework "Foundation"
    use scripting additions
    on run argv
        set arguments to (current application's NSProcessInfo's processInfo's arguments) as list
        do shell script "open -a \"PDF Expert\" " & item 3 of arguments
        activate application "PDF Expert"
        tell application "System Events"
            tell process "PDF Expert"
                click menu item "Go to Page..." of menu 1 of menu bar item "Go" of menu bar 1
                keystroke item 4 of arguments
                key code 36
            end tell
        end tell
    end run

I have taken some pains to ensure that Emacs is running in my usual login environment including PATH, so I'm reasonably confident that isn't the problem (but I can supply my Emacs startup script if requested). I have tried it with and without dbus running. I have tried putting delays all over. I have tried putting popup messages at various places, and found that the script just seems to stop dead before or during the first tell.

I suspect there might be a permissions issue. Emacs I think has all the permissions it needs, but I don't understand enough about the situation to know how exactly the script is forking from Emacs, or how to enable the necessary permissions.

EDIT: I tried Emacs in an iTerm2 windows, invoking with /Applications/MacPorts/EmacsMac.app/Contents/MacOS/Emacs -nw, and the pdfe script runs perfectly, after I enabled Accessibility for iTerm2. I have now also enabled Accessibility in Terminal, and my Emacs GUI version still does not have the right permissions.

EDIT 2: I tried running GUI Emacs by invoking with /Applications/MacPorts/EmacsMac.app/Contents/MacOS/Emacs, and the pdfe script again runs perfectly, so it seems the issue is with the way I start up GUI Emacs. So here is my startup script, which I based on Emacs Wiki with a small modification to stop the Automator gear from turning indefinitely:


cd # start in my home directory

if pgrep -U $(id -u) $(basename $EMACS) >/dev/null; then
  if [ "$#" -eq 0 ]; then
    # set -- -e '(select-frame-set-input-focus (car (or (visible-frame-list) (frame-list)))'
    echo "\"$EMACSCLIENT\" -e '(select-frame-set-input-focus (car (or (visible-frame-list) (frame-list))))'" | bash --login -s "$@" ;
    echo "\"$EMACSCLIENT\" -n \"\$@\"" | bash --login -s "$@" ; 
  nohup bash --login -c "$EMACS "$@"" >/dev/null 2>&1 &

1 Answer 1


After trying it out for a while, I've found that the script works fine until PDF Expert encounters an error of some kind, then PDF Expert seems to stop taking the go to page command. I've found that closing and then opening PDF Expert (or just the window in question) seems to reset it, and then the script works fine until the next error.

The best way to solve this problem once and for all is to modify PDF Expert to accept a command line option to "go to page ...". I've submitted a feature request to them. In the mean time, I'll check out some other PDF viewers, and I'll just have to remember to close the PDF window(s) when it starts acting up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.