Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Print Terminal Output to A PDF file

35 views
Skip to first unread message

Matthew W

unread,
Sep 21, 2017, 2:44:47 AM9/21/17
to
Hey I created an applescript that outputs info to the terminal window, and now I'm trying to find if there is a way to automatically take the information that is output to Terminal and save that info as a PDF file?

I'm somewhat new to AppleScripting (and haven't use the terminal much since college), so I'm trying to figure out if this can be done easily?

Thanks for any help

Jolly Roger

unread,
Sep 21, 2017, 11:52:02 AM9/21/17
to
Why bother scripting the Terminal application directly if all you want
to do is run a command-line program, which you can do directly in
AppleScript?

Why bother with a PDF if the output of any command-line program is just
plain text?

You can use the "do shell script" command to run any command-line
programs you want and send the output to a plain text file.

For instance, here's a simple script that runs the "top" command and
puts the output of it into a plain text file on the desktop:

-- begin script
property outputFilename : "top_output.txt"
property outputFile : (the POSIX path of the (path to the desktop) &
outputFilename) as text
property topCommand : "top -u -l 2 -n 21 -ncols 17 > " & the quoted form
of outputFile

set commandOutput to do shell script topCommand
-- end script

As you can see there are three properties at the top of the script:

* outputFilename: the name of the text file containing the output
* outputFile: the full path of the output text file
* topCommand: the command-line program to run

Notice that the topCommand uses the > command-line syntax followed by
the path to the output file, which causes the output of the "top"
command to be placed into a new text file at that path.

The "do shell script" line at the end actually executes the command,
which in turn sends the command output to the text file on the desktop.

--
E-mail sent to this address may be devoured by my ravenous SPAM filter.
I often ignore posts from Google. Use a real news client instead.

JR
0 new messages