[Usability] Re: Can the GNOME desktop survive an encounter with my parents?



On 8/26/05, Vidar Braut Haarr <vhaarr+usability gmail com> wrote:
> 7. Rightclicks on a picture, "Send To" uses Evolution. He wants to be
> able to select X images, Send To->Email Recipient and it should open a
> Thunderbird (his default e-mail client) Compose window with the images
> attached.

Since I was unable to find a solution to this and another thing my
parents want[1], I set down to write some scripts to solve them.

Nautilus-actions[2][3] version 0.6 proved invaluable here. It makes it
very easy to create new context menu items with no
C/make/god-knows-what knowledge.

Anyway, the two scripts, sendtoemail.py and movetofolder.py are
attached to this e-mail.

I think I'll create a "view slideshow here" script this weekend, but
the selection filter settings in nautilus-actions are currently too
limited. Hopefully this will be fixed in 0.7.

Have fun, and remember, the scripts are provided as-is with no
warranty (but they work fine here) :-D

1: "Move to" in the Nautilus context menu. I have explained Copy/Paste
and moving by dragging, but both these requires you to change the
current context in a drastic way (navigate to another folder with your
primary browser window or open a new window on the desktop.)
2: <http://www.grumz.net/?q=taxonomy/term/2/9>
3: <http://cvs.gnome.org/viewcvs/nautilus-actions/>

-- 
Vidar Braut Haarr
"Programmers don't die, they
just GOSUB without RETURN."
#!/usr/bin/python

# "Move to folder" script for nautilus-actions 0.6 or later.
#
# Make a new action in NACT that has the parameter "%d %m" (without
# the quotes) to use this script. It supports both files and folders.
#
# * If a file exists in the target directory with the same name, the file will
#   not be moved. 'mv' is executed with --reply=no.
#
# DISCLAIMER:
# This script will eat your harddrive and set your computer on fire.
#
# LICENSE
# GNU General Public License
#
# Author: Vidar Braut Haarr <vhaarr+trap gmail com>

# $1 should be the path, like "/path/to"
# $2-X should be the filenames

# Configure these to your system:
ZENITY = "/usr/bin/zenity"
DISPLAY = ":0.0"

# "Moving <file>"
PROGRESS_TITLE = "Flytter "
# "Move to ..."
SELECT_TITLE = "Flytt til ..."
# "<destination> already exists. Overwrite?"
OVERWRITE_PROMPT = " finnes allerede. Vil du overskrive?"
# "Overwrite"
OVERWRITE_TITLE = "Skriv over"

# Set to True to debug log to /home/user/.log_movetofolder.txt
DEBUG = True

def bashify(filename):
	return "\\" + string.join(list(filename), "\\")

def fileExists(filename):
	try:
		file = open(filename)
	except IOError, v:
		(code, message) = v
		# 21 means it's a directory, and it exists
		if code == 21:
			exists = 1
		else:
			exists = 0
	else:
		exists = 1
	return exists

def closeLogAndExit():
	if DEBUG == True: log.close()
	sys.exit()

def printUsageAndExit():
	sys.stdout.write('usage: movetofolder.py [DIRECTORY] [FILENAME]...\n'                         \
                     'Directory is the directory that holds all the files. The script does not\n' \
                     'support sending files from multiple directories.\n\n'                       \
                     'The script was made to be used with nautilus-actions 0.6. Configure it\n'   \
                     'with command parameters \'%d %m\', and it should work out of the box.\n\n'  \
                     'movetofolder.py moves the given files to a directory as provided\n'         \
					 'by Zenity.\n\n'                                                             \
					 'Please read the comments in the script itself.\n'                           \
					 'Author: Vidar Braut Haarr <vhaarr+trap gmail com>\n')
	closeLogAndExit()

def logwrite(text, error=False):
	if DEBUG == True: log.write(DATETIME + ": " + text)
	if error == True:
		sys.stderr.write("ERROR: " + text)
	else:
		sys.stdout.write("LOG: " + text)

import sys
import os
import string
import urllib
from datetime import datetime
if DEBUG == True: DATETIME = datetime.today().isoformat()

cmdList = sys.argv

# Just pop one to get the script name $0 out of the queue
SCRIPTNAME = cmdList.pop(0)

if DEBUG == True:
	log = file(os.environ['HOME'] + "/.log_movetofolder.txt", "a+")
	logwrite("cmdList: " + str(cmdList) + "\n")

# Check to see that we have at least 2 arguments:
# <path> <file1>...<fileX>
if len(cmdList) < 2:
	logwrite(SCRIPTNAME + ': Not enough parameters.\n', True)
	printUsageAndExit()

# Check that the given path is a directory that exists
path = urllib.unquote(cmdList.pop(0))
if os.path.exists(path) == False:
	logwrite(SCRIPTNAME + ': ' + path + ' does not exist.\n', True)
	printUsageAndExit()

# Check that we have Zenity, so we can provide a folder picker.
if fileExists(ZENITY) == 0:
	logwrite(SCRIPTNAME + ': ' + ZENITY + ' not found.\n', True)
	closeLogAndExit()

# List of files to be moved.
files = []
filename = ""

for arg in cmdList:
	filename = path + "/" + arg
	if DEBUG == True: logwrite("Checking for entity [" + filename + "].\n")
	if fileExists(filename) == 1:
		# Alright, we have a file - add it to the list of files.
		if DEBUG == True: logwrite("Exists.\n")
		files.append(filename)

if DEBUG == True: logwrite("Entities: " + str(files) + ".\n")

saveDirectoryHandle = os.popen(ZENITY + " --file-selection --directory --filename=\"" + path + "/\" --title=\"" + SELECT_TITLE + "\"")
saveDirectory = string.replace(saveDirectoryHandle.readline(),"\n","")
saveDirectoryHandle.close()

if DEBUG == True: logwrite("Save directory: " + saveDirectory + ".\n")

if os.path.exists(saveDirectory) == False:
	logwrite(SCRIPTNAME + ": " + saveDirectory + " does not exist.", True)
	closeLogAndExit()

progressHandle = os.popen(ZENITY + " --progress --pulsate --text=\"" + PROGRESS_TITLE + "\" --percentage=10 --auto-close", "w")
# We need to write something to get the meter going. Doesn't matter what, as long as it's not '100'.
progressHandle.write('10\n')

for file in files:
	# Move file.

	if DEBUG == True: logwrite("Moving " + file + ".\n")

	os.system("mv --reply=no " + bashify(file) + " " + bashify(saveDirectory))
	progressHandle.write("#" + PROGRESS_TITLE + file)

    # Do we want to overwrite ?
	#lineFromMv = childStdoutHandle.readline()
	#overwrite = (string.find(lineFromMv, "overwrite") != -1)

	#if DEBUG == True: logwrite("Line from mv: " + lineFromMv + ".\n")
	#if DEBUG == True: logwrite("Need overwrite? " + str(overwrite) + ".\n")

	#if overwrite == True:
	#	retval = os.system(ZENITY + " --question --text=\"" + saveDirectory + file + "\"" + OVERWRITE_PROMPT + "\n")
	#	if retval == 1:
	#		childStdinHandle.write("no\n")
	#	else:
	#		childStdinHandle.write("yes\n")
	
	#childStdinHandle.close()
	#childStdoutHandle.close()

# Make the progress complete and close the handle.
progressHandle.write('100\n')
progressHandle.close()

if DEBUG == True: logwrite("Done.\n\n")
if DEBUG == True: log.close()

# EOF
#!/usr/bin/python

# "Send files to contact" script for nautilus-actions 0.6 or later.
#
# Make a new action in NACT that has the parameter "%s %d %m" (without
# the quotes) to use this script.
#
# The script does not support sending files from multiple directories
# (which could be possible if launched from a terminal instead of nautilus)
# because nautilus-actions has some limitations in how it passes the files.
#
# TODO
#  * Make it ZIP the files before sending them.
#
# DISCLAIMER:
# This script will eat your harddrive and set your computer on fire.
#
# LICENSE
# GNU General Public License
#
# Author: Vidar Braut Haarr <vhaarr+trap gmail com>

# $1 should be the scheme, like "file"
# $2 should be the path, like "/path/to"
# $3-X should be the filenames

# Configure these to your system:
MOZ_TB = "/usr/bin/mozilla-thunderbird"
MOZ_TB_XREMOTE = "/usr/lib/mozilla-thunderbird/mozilla-thunderbird-xremote-client"
# Would it be possible to use "/usr/bin/env python", and it would use the
# current display automatically ?
DISPLAY = ":0.0"

# Set to True to enable logging to /home/user/.log_sendtoemail.txt
DEBUG = True

def fileExists(filename):
	try:
		file = open(filename)
	except IOError, v:
		if DEBUG == True:
			try:
				(code, message) = v
			except:
				code = 0
				message = v
			logwrite(str(message) + " (" + str(code) + ")\n")
		exists = 0
	else:
		exists = 1
	return exists

def closeLogAndExit():
	if DEBUG == True: log.close()
	sys.exit()

def printUsageAndExit():
	sys.stdout.write('usage: sendtoemail.py [file|sftp|ftp|smb|dav] [DIRECTORY] [FILENAME]...\n'     \
                     'Directory is the directory that holds all the files. The script does not\n'    \
                     'support sending files from multiple directories.\n\n'                          \
                     'The script was made to be used with nautilus-actions 0.6. Configure it\n'      \
                     'with command parameters \'%s %d %m\', and it should work out of the box.\n\n'  \
                     'sendtoemail.py launches Mozilla Thunderbird, opening a new compose\n'          \
                     'window with the specified files attached to the new e-mail. If Mozilla\n'      \
                     'Thunderbird is already running, we use it through XRemote instead of\n'        \
                     'launching a new instance.\n\n'                                                 \
					 'Please read the comments in the script itself.\n'                              \
					 'Author: Vidar Braut Haarr <vhaarr+trap gmail com>\n')
	closeLogAndExit()

def logwrite(text, error=False):
	if DEBUG == True: log.write(DATETIME + ": " + text)
	if error == True:
		sys.stderr.write(text)
	else:
		sys.stdout.write(text)

import sys
import os
import string
import urllib
from datetime import datetime
if DEBUG == True: DATETIME = datetime.today().isoformat()

cmdList = sys.argv

# Just pop one to get the script name $0 out of the queue
SCRIPTNAME = cmdList.pop(0)

if DEBUG == True:
	log = file(os.environ['HOME'] + "/.log_sendtoemail.txt", "a+")
	logwrite("cmdList: " + str(cmdList) + "\n")

# Check to see that we have at least 3 arguments:
# <scheme> <path> <file1>...<fileX>
if len(cmdList) < 3:
	logwrite(SCRIPTNAME + ': Not enough parameters.\n', True)
	printUsageAndExit()

# Check that the given scheme is supported
supportedSchemes = ['file','sftp','smb','ftp','dav']
scheme = cmdList.pop(0)
if scheme in supportedSchemes == False:
	logwrite(SCRIPTNAME + ': ' + scheme + ' is not a supported scheme.\n', True)
	printUsageAndExit()
scheme = scheme + "://"

# Check that the given path is a directory that exists
path = urllib.unquote(cmdList.pop(0))
if os.path.exists(path) == False:
	logwrite(SCRIPTNAME + ': ' + path + ' does not exist.\n', True)
	printUsageAndExit()

if fileExists(MOZ_TB) == 0:
	logwrite(SCRIPTNAME + ': ' + MOZ_TB + ' not found.\n', True)
	closeLogAndExit()

if fileExists(MOZ_TB_XREMOTE) == 0:
	logwrite(SCRIPTNAME + ': ' + MOZ_TB_XREMOTE + ' not found.\n', True)
	closeLogAndExit()

# Need to compensate for files with one or more spaces in the filename.
# ... after some research, it seems that we have to compensate for
# files having %20 as well. The first file we get can have spaces, but
# file 2-> has %20 instead ... this must be nautilus[-actions]'s doing.
arguments = "attachment='"
filename = ""

for arg in cmdList:
	filename = path + "/" + arg		
	if DEBUG == True: logwrite("Checking for file [" + urllib.unquote(filename) + "].\n")
	if fileExists(filename) == 1:
		# Alright, we have a file - add it to arguments and clear building string.		
		if DEBUG == True: logwrite("Exists.\n")
		arguments = arguments + scheme + urllib.quote(filename) + ","

arguments = arguments + "'"

if DEBUG == True: logwrite("Arguments: " + arguments + "\n")

# Now, check if TB is running already.
# 0 means it's running
# 512 means it's not running
retval = os.system(MOZ_TB_XREMOTE + " -a 'mozilla-thunderbird' 'ping()'")
if retval == 0:
	os.system(MOZ_TB_XREMOTE + " \"xfeDoCommand(composemessage," + arguments + ")\"")
elif retval == 512:
	os.system(MOZ_TB + " --display=" + DISPLAY + " -compose \"" + arguments + "\"")
else:
	logwrite(SCRIPTNAME + ": Return value " + retval + " from " + MOZ_TB_REMOTE + " unknown. Accepted values are 0 and 512.", True)

if DEBUG == True: logwrite("Done.\n\n")
if DEBUG == True: log.close()

# EOF


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]