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

How to open folder - Win/Linux/Mac ?

65 views
Skip to first unread message

Aldo Buratti

unread,
Mar 9, 2017, 5:38:46 PM3/9/17
to
At the end of a long computation, I need to show all the results (several files) in a given folder.
On Windows I can do something like this
exec {*}[auto_execok start] c:/tmp
or
exec cmd /C start c:/tmp

What are the equivalent commands for Linux and Mac ?

Aldo

Christian Gollwitzer

unread,
Mar 10, 2017, 12:22:54 AM3/10/17
to
Am 09.03.17 um 23:38 schrieb Aldo Buratti:
Linux: xdg-open
OS X: open

These are the command line tools for running some arbitrary "thing",
from within Tcl you need to prepend with exec, of course.

Christian

Paul Obermeier

unread,
Mar 10, 2017, 2:29:35 AM3/10/17
to
I have this proc in my Tcl swiss-knife:

proc StartFileBrowser { dir } {
if { $::tcl_platform(platform) eq "windows" } {
set browserProg "explorer"
} elseif { $::tcl_platform(os) eq "Linux" } {
set browserProg "konqueror"
} elseif { $::tcl_platform(os) eq "Darwin" } {
set browserProg "open"
} elseif { $::tcl_platform(os) eq "SunOS" } {
set browserProg "filemgr -d"
} elseif { [string match "IRIX*" $::tcl_platform(os)] } {
set browserProg "fm"
} else {
set browserProg "xterm -e ls"
}
if { [file isdirectory $dir] } {
eval exec $browserProg [list [file nativename $dir]] &
}
}

Paul

Ralf Fassel

unread,
Mar 10, 2017, 8:08:25 AM3/10/17
to
* Paul Obermeier <ober...@poSoft.de>
| I have this proc in my Tcl swiss-knife:
>
| proc StartFileBrowser { dir } {
--<snip-snip>--
| } else {
| set browserProg "xterm -e ls"
| }
| if { [file isdirectory $dir] } {
| eval exec $browserProg [list [file nativename $dir]] &
| }
| }

Just out of curiosity: on which platform/universe is
exec xterm -e ls &
useful?

On my Linux system an xterm appears and disappears instantly -
too short for my human eyes to grok... :-)

R'

Rich

unread,
Mar 10, 2017, 8:10:20 AM3/10/17
to
Paul Obermeier <ober...@posoft.de> wrote:
> I have this proc in my Tcl swiss-knife:
>
> proc StartFileBrowser { dir } {
> if { $::tcl_platform(platform) eq "windows" } {
> set browserProg "explorer"
> } elseif { $::tcl_platform(os) eq "Linux" } {
> set browserProg "konqueror"
> } elseif { $::tcl_platform(os) eq "Darwin" } {
> set browserProg "open"
> } elseif { $::tcl_platform(os) eq "SunOS" } {
> set browserProg "filemgr -d"
> } elseif { [string match "IRIX*" $::tcl_platform(os)] } {
> set browserProg "fm"
> } else {
> set browserProg "xterm -e ls"
> }
> if { [file isdirectory $dir] } {
> eval exec $browserProg [list [file nativename $dir]] &
> }
> }

And as an FYI, it would fail on my Slackware systems as there is no
"konqueror" (I purposefully do not install KDE).

Rich

unread,
Mar 10, 2017, 8:56:34 AM3/10/17
to
The -e option tells xterm to execute the command, and when the command
is done, xterm exits. If you want it to hang around, then the command
has to wait for user interaction in some way:

xterm -e bash -c 'ls ; read -p "Press Return" junk'

Christian Gollwitzer

unread,
Mar 10, 2017, 1:59:19 PM3/10/17
to
Am 10.03.17 um 14:07 schrieb Rich:
This is why I proposed xdg-open, which should come with any desktop
environment, since it is part of freedesktop.org
Similar to "start" on Windows and "open" on Darwin, it can "run" all
kinds of "things". Folder paths open a file manager window, URLs open a
browser, files open the associated program, so for instance, you could
play a soundfile with

xdg-open some.mp3
or open a text processor with
xdg-open some-word.docx

Christian

Aldo Buratti

unread,
Mar 10, 2017, 5:26:14 PM3/10/17
to
@Christian
Thank you for the Linux suggestion. I only added "2>/dev/null" in order to discard some diagnostic message

# open folder /tmp
exec xdg-open /tmp 2>/dev/null

Thanks again
Aldo
0 new messages