Actually, a better way to do it for Python or Ruby would be to use the exec functions. That way the interpreter (and its overhead) isn't hanging around in the background, and you see the program correctly in the program list instead of just the interpreter. Also, nautilus.real should be passed '--nodesktop' and there should be some bounds checking on argv.
========
Python version:
#!/usr/bin/python
import os, sys
## we need the explicit path to tell exec* in arg 0 ## so that when thunar/nautilus takes control of ## the process, the right name is shown in the ## process list / pidof / &c, else 'pidof thunar' ## returns null
## set the path explicitly thunar_bin = '/usr/bin/thunar' ## else uncomment below #pipe = os.popen('which thunar') #thunar_bin = pipe.read().strip() #pipe.close()
## set the path explicitly nautil_bin = '/usr/bin/nautilus.real' ## else uncomment below #pipe = os.popen('which nautilus.real') #nautil_bin = pipe.read().strip() #pipe.close()
## we need the explicit path to tell exec in arg 0 ## so that when thunar/nautilus takes control of ## the process, the right name is shown in the ## process list / pidof / &c, else 'pidof thunar' ## returns null
## set the path explicitly thunar_bin = '/usr/bin/thunar' ## else uncomment below #thunar_bin = `which thunar`.chomp()
## set the path explicitly nautil_bin = '/usr/bin/nautilus.real' ## else uncomment below #nautil_bin = `which nautilus.real`.chomp()
if (ARGV.empty?) exec([thunar_bin, thunar_bin]) elsif (ARGV[0].nil? or ARGV[0][0,1] == '/') exec([thunar_bin, thunar_bin], ARGV[0]) elsif (ARGV.length > 1 and ARGV[1][0..6] == 'file://') exec([thunar_bin, thunar_bin], ARGV[1]) else exec([nautil_bin, nautil_bin], *(['--no-desktop'] + ARGV)) end
Actually, a better way to do
Actually, a better way to do it for Python or Ruby would be to use the exec functions. That way the interpreter (and its overhead) isn't hanging around in the background, and you see the program correctly in the program list instead of just the interpreter. Also, nautilus.real should be passed '--nodesktop' and there should be some bounds checking on argv.
========
Python version:
#!/usr/bin/python
import os, sys
## we need the explicit path to tell exec* in arg 0
## so that when thunar/nautilus takes control of
## the process, the right name is shown in the
## process list / pidof / &c, else 'pidof thunar'
## returns null
## set the path explicitly
thunar_bin = '/usr/bin/thunar'
## else uncomment below
#pipe = os.popen('which thunar')
#thunar_bin = pipe.read().strip()
#pipe.close()
## set the path explicitly
nautil_bin = '/usr/bin/nautilus.real'
## else uncomment below
#pipe = os.popen('which nautilus.real')
#nautil_bin = pipe.read().strip()
#pipe.close()
if (len(sys.argv) == 1):
os.execl(thunar_bin, thunar_bin)
elif (not sys.argv[1] or sys.argv[1][0] == '/'):
os.execl(thunar_bin, thunar_bin, sys.argv[1])
elif (len(sys.argv) > 2 and sys.argv[2][0:7] == 'file://'):
os.execl(thunar_bin, thunar_bin, sys.argv[2])
else:
os.execv(nautil_bin, [nautil_bin, '--no-desktop'] + sys.argv[1:])
========
Ruby version:
#!/usr/bin/ruby
## we need the explicit path to tell exec in arg 0
## so that when thunar/nautilus takes control of
## the process, the right name is shown in the
## process list / pidof / &c, else 'pidof thunar'
## returns null
## set the path explicitly
thunar_bin = '/usr/bin/thunar'
## else uncomment below
#thunar_bin = `which thunar`.chomp()
## set the path explicitly
nautil_bin = '/usr/bin/nautilus.real'
## else uncomment below
#nautil_bin = `which nautilus.real`.chomp()
if (ARGV.empty?)
exec([thunar_bin, thunar_bin])
elsif (ARGV[0].nil? or ARGV[0][0,1] == '/')
exec([thunar_bin, thunar_bin], ARGV[0])
elsif (ARGV.length > 1 and ARGV[1][0..6] == 'file://')
exec([thunar_bin, thunar_bin], ARGV[1])
else
exec([nautil_bin, nautil_bin], *(['--no-desktop'] + ARGV))
end