user2640480
user2640480

Reputation: 2019

use tcl script to open a txt file (to make a txt file pop out on the screen)

How to really "open" the txt file (already know the file path), I mean, to pop out on the screen, by writing a tcl script? Thank you!

Upvotes: 1

Views: 2105

Answers (2)

Donal Fellows
Donal Fellows

Reputation: 137667

Invoking the system “preferred” text editor is relatively easy, but not very portable. Assuming that $theFilename contains the name of the file as Tcl understands it, and that it is not a file on one of Tcl's virtual filesystems:

Mac

exec open [file normalize $theFilename]

Unix/Linux

exec xdg-open [file normalize $theFilename]

Or, if you're in a terminal and like the classic method:

exec $::env(EDITOR) [file normalize $theFilename] <@stdin >@stdout 2>@stderr

(You probably ought to also check for the VISUAL environment variable before the EDITOR environment variable. Or just fire it into the GUI with xdg-open…)

Windows

exec {*}[auto_execok start] "" [file nativename [file normalize $theFilename]]

Yes, that empty argument is necessary (especially when a directory or file has a space in it); start has horrible syntax.

Upvotes: 2

Hai Vu
Hai Vu

Reputation: 40743

I assume by open, you meant open using an application/program. On Windows:

exec notepad.exe /path/to/file.txt

On Mac:

exec open /path/to/file.txt             ;# Open using default application

or:

exec open -a TextEdit /path/to/file.txt ;# Open using a specific application

Upvotes: 0

Related Questions