User:Rogueai
This page currently serves as my "braindump" to keep track of various findings while I explore the AS/400 world.
All the information available here is tested on the machine available to me: AS/400 9406-170 V4R2
Screenshot script for tn5250j
While researching and trying out new things, I often find myself taking screenshots or saving the screen content as text. To ease this process I wrote a simple jython script that can be used with tn5250j.
The script saves the current screen as both a txt and a png file.
The script must be placed inside $HOME/.tn5250j/scripts
as a python source file, e.g.: myScript.py
.
It can then be referenced from the "Macros" menu. A keybind can also be assigned to further ease the process.
Currently, output files are stored in $HOME/Documents/as400/screens
, with the file names being in the format screen-<yyyyMMdd-HHmmss>.[txt|png]
.
I'd suggest reviewing the script and customizing it to your liking before running it for the first time.
from org.tn5250j.tools.encoder import EncodeComponent
from java.text import SimpleDateFormat
from java.util import Date
from java.lang import String
from java.lang import StringBuffer
from java.lang import System
from java.io import File
def fillBuffer(screen, sb):
chars = screen.getScreenAsChars()
c = screen.getColumns()
l = screen.getRows() * c
col = 0
x = 0
while x < l:
sb.append(chars[x])
if col == c:
sb.append('\n')
col = 0
x += 1
col += 1
print "--------------- tn5250j printScreen script start ------------"
home = System.getProperty("user.home")
filename = 'screen-' + SimpleDateFormat("yyyyMMdd-HHmmss").format(Date())
filepath = home + '/Documents/as400/screens/' + filename
screen = _session.getScreen()
sb = StringBuffer()
fillBuffer(screen, sb)
screen_txt = open(filepath + '.txt','w')
screen_txt.write(sb.toString())
screen_txt.close()
screen_png = open(filepath + '.png','w')
EncodeComponent.encode(EncodeComponent.PNG, _session, screen_png)
screen_png.close()
print "---------------- tn5250j printScreen script end -------------"