summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/psviewer/psviewer.vbs
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/psviewer/psviewer.vbs')
-rw-r--r--Master/texmf-dist/scripts/psviewer/psviewer.vbs65
1 files changed, 65 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/psviewer/psviewer.vbs b/Master/texmf-dist/scripts/psviewer/psviewer.vbs
new file mode 100644
index 00000000000..3df3ca29a53
--- /dev/null
+++ b/Master/texmf-dist/scripts/psviewer/psviewer.vbs
@@ -0,0 +1,65 @@
+' Written by Siep Kroonenberg in 2020 and placed in the Public Domain
+
+option explicit
+On Error Resume next
+
+dim oWsh, oFS, sTmp, oArgs, f, fname, tf, i, msg
+
+set oWsh = wscript.createobject( "wscript.Shell" )
+Set oFS = CreateObject("Scripting.FileSystemObject")
+sTmp=oWsh.ExpandEnvironmentStrings("%Temp%")
+
+Set oArgs = wscript.arguments
+If oArgs.count = 0 Then
+ msg = "Psviewer is a simple script which converts its argument to a " & _
+ " temporary pdf and displays it in the default pdf viewer." _
+ & vbcrlf & vbcrlf & _
+ "Double-clicking an .eps- or .ps file should result in viewing the " & _
+ "converted file. If this does not work, then try right-click and " & _
+ "'Open with', which should give you the option to set psviewer as " & _
+ "default program for .[e]ps files."
+ MsgBox msg, 0, "Psv: no argument"
+ wscript.quit
+End If
+f = oArgs( 0 )
+fname = oFS.getfile( f ).Name
+
+Randomize
+
+' find a name for a new temporary pdf file
+i = 0
+do
+ tf = sTmp & "\" & fname & "-" & Int(100000 * Rnd) & ".pdf"
+ i = i + 1
+ If Not oFS.FileExists( tf ) then
+ Exit do
+ else
+ tf = ""
+ if i >= 500 Then
+ Exit Do
+ End If
+ End If
+Loop
+If tf = "" Then
+ wscript.echo "Cannot create temporary pdf"
+ wscript.quit
+End If
+
+' create temporary pdf
+If LCase( Right( fname, 4 )) = ".eps" Then
+ If oWsh.run( "kpsewhich -format texmfscripts epstopdf.pl", 0, true ) = 0 Then
+ oWsh.run "epstopdf " & oArgs( 0 ) & " " & tf, 0, true
+ Else
+ oWsh.run "gswin32c -q -dNOPAUSE -dBATCH -P- -dSAFER -sDEVICE#pdfwrite -dEPSCrop -sOutputFile#" & tf & " -f " & f, 0, true
+ End if
+Else
+ oWsh.run "gswin32c -q -dNOPAUSE -dBATCH -P- -dSAFER -sDEVICE#pdfwrite -sOutputFile#" & tf & " -f " & f, 0, true
+End If
+
+' open temporary pdf
+If oFS.fileexists(tf) Then
+ oWsh.run( tf )
+Else
+ MsgBox f & " could not be converted," & vbcrlf & _
+ "is probably not valid PostScript", 0, "Error"
+End If \ No newline at end of file