运行python程序总是要打开终端,cd到目录,输入python $file,真的很麻烦,找了一下资料,发现如下:
在/home/ydf/.local/share/nautilus/scripts/文件夹下新建run_on_python和run_on_python_helper文件,内容如下:
# run_on_python
gnome-terminal -e "expect /home/ydf/.local/share/nautilus/scripts/run_on_python_helper $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"
# run_on_python_helper
#!/usr/bin/expect -f
# Get a Bash shell
spawn -noecho bash
# Wait for a prompt
expect "$ "
set file [lindex $argv 0]
# Type something
send "python $file\n"
# Hand over control to the user
interact
exit
给run_on_python文件增加可执行权限:右键=>Properties=>Permissions=>Allow executing as files as program。
建立测试文件:lalala.py,内容如下:
import time
for i in range(10):
print 'klalala'
time.sleep(1)
右键lalala.py=>Scripts=>run_on_python,即可看到效果了。
ubuntu15.04右键打开终端:http://www.linuxdiyf.com/linux/13159.html
为ubuntu Kylin 15.04 64位版添加“以管理员权限打开”的右键菜:http://www.linuxdiyf.com/linux/11860.html
Ubuntu Kylin 15.04下右键点启动栏顶目弹出菜单,移动鼠标后菜单:http://www.linuxdiyf.com/linux/11738.html
Ubuntu右键菜单改造:http://www.linuxdiyf.com/linux/8721.html
Ubuntu下右键“发送到其它电脑”:http://www.linuxdiyf.com/linux/926.html