PDA

View Full Version : Applescript - close current file


the_shrubber
04-09-2002, 11:36 AM
Hi,

I'm trying to make it so that vim's "make" command latexs my tex file, closes the current TexShop (Preview.app but better) window, and then opens it with the new pdf. Bottom line is that i want to refresh-view the pdf that gets generated. In order to do this, it seems i need to get an application to close the current window, but not quit.

Right now, i have osascript -e 'tell application "TexShop" to quit' which works, but it means TexShop and relaunch later when i call open -a. Is there an Applescript way (or whatever) to make Mac apps close their current window, but not quit?

the_shrubber
04-09-2002, 01:09 PM
Geez, i'm not trying to be one of those annoying people, it's just that sometimes you only figure out exactly the right search-engine stuff AFTER you ask for help.

Anyway, the answer:
tell application "TexShop" to close the front window

the only thing is that this complains if there is no front window, but i just ignore any errors for now... much obliged if you can craft a one-liner like ' if application "TexShop" has a front window, tell application "TexShop" to close the front window' "

Thanks anyway.

xchanyazy
04-09-2002, 01:23 PM
I got this to work with M$ Excel

tell application "Microsoft Excel"
Activate
if Window 1 exists then
Close Window 1
end if
end tell

the_shrubber
04-25-2002, 01:16 PM
i have an even handier one-liner for my purposes (i.e editing LaTeX in vim and running Preview)... this makes it work even if TeXShop is minimized.

--------

tell application "TeXShop" to close every window

(followed by open -a TeXShop file.pdf)

----

You should be able to substitute "Preview" for TeXShop

the_shrubber
09-19-2002, 08:37 AM
Here is a refinement that precises WHICH window i want to close. This is useful because i sometimes have a blank document open from which i play with TexShop's LateX palette, so closing every window would also close that.

tell application "TeXShop" to close every window whose name is "foo"

my vimrc has "foo" set to expand("%:t:r").'.pdf'

little things make me happy

the_shrubber
09-19-2002, 08:41 AM
my thanks to whoever makes this vimrc bit nicer in any way whatsoever


let l:fileroot=expand("%:p:r")
let l:filerootLite=expand("%:t:r")
let l:closeViewerCmd="osascript -e 'tell application ".'"TexShop" to close every window whose name is "'.l:filerootLite.'.pdf"'."'"
let l:openViewerCmd='open -a TexShop '.l:fileroot.'.pdf'
let l:dviPdfCmd='dvipdf '.l:fileroot.'.dvi'
let l:viewCmd=l:closeViewerCmd.' ; '.l:openViewerCmd
let l:ppowerCmd='ppower4 '.l:fileroot.'.pdf '.l:fileroot.'.ppower4'
let l:ppowerCmd=l:ppowerCmd.'; mv -f '.l:fileroot.'.ppower4 '.l:fileroot.'.pdf'
exec 'map <buffer> ,b :!bibtex'.' '.l:fileroot.'<Enter>'
exec 'map <buffer> ,p :!'.l:ppowerCmd.';'.l:viewCmd.'<Enter><Enter>'
exec 'map <buffer> ,f <Esc>^a% <Esc>73a-<Esc><Esc>o\foilhead{}<Esc><Esc>i'

exec 'map <buffer> ,v :!'.l:viewCmd.'<Enter><Enter>'
let &l:makeprg='pdflatex --interaction nonstopmode'.' '.l:fileroot.'.tex'
let &l:makeprg=&l:makeprg.' && '.l:viewCmd