On macOS, you can build a graphic tool which show the stack after running a code.
(Disclaimer: I was helped with an AI for a part of the AppleScript code, specially the line set shellCommand to ...
, as I needed a stack viewer for learn the PostScript code).
Input stack (ex. "3 4")
.Then click on the first "Ask for input" (cercled in red here):
This will add the input stack in the Text object.
Notice the space between the two graphical variables, it's very important. You can know to what "Ask for Input" each object is by click on it (not right-click), then choose "Reveal". You can also rename it with this method).
It automatically takes the previous Text object as input.
Note that adding the "Run AppleScript" can replace the icon choose for the Shortcut by the AppleScript icon. You can change the icon again (click on it, see point 1).
completeCommand
receive the value in the Text object):on run {completeCommand}
-- Prepare the PostScript command for Ghostscript
set fullPSCode to (completeCommand as text) & " pstack"
-- Run Ghostscript via do shell script with the full path
try
set shellCommand to "echo " & quoted form of fullPSCode & " | /usr/local/bin/gs -q -sDEVICE=nullpage - 2>&1"
set output to do shell script shellCommand
-- Define the delimiters to include \r (carriage return)
set AppleScript's text item delimiters to {return, linefeed, ASCII character 13}
set resultLines to text items of output
-- Reverse the order to go from the base to the top
set reversedLines to reverse of resultLines
-- Build the final result
set cleanResult to ""
repeat with thisLine in reversedLines
if length of thisLine > 0 then
set cleanResult to cleanResult & thisLine & " "
end if
end repeat
-- Clean the final space and reset the delimiters
if length of cleanResult > 0 then
set cleanResult to text 1 thru -2 of cleanResult
end if
set AppleScript's text item delimiters to ""
display dialog "Output Stack: " & cleanResult buttons {"OK"} default button "OK"
on error errMsg
display dialog "Error: " & errMsg buttons {"OK"} default button "OK" with icon stop
end try
end run
You can click on the Hammer icon of the AppleScript action to "compile" the code. If the code is syntactically colored, then there is no error.
In this code /usr/local/bin/gs
this the path to the gs
command. You need to use the absolute path.
Enter the input stack:
Click done, enter the PostScript code, example add
, click done, and you have the output stack:
Another example:
1 2 3 4 5 6
pop dup mul 3 1 roll
Output stack: