Xfce Forum

Sub domains
 

You are not logged in.

#1 2012-02-04 23:58:11

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

[Solved] Create date-stamped file copy with Thunar custom action

I haven't posted here for a while, but I'd be grateful for help with this one. Running Xfce 4.6.2 and Thunar 1.0.2 in Debian Squeeze.

I can back up a selected file to a 'backups' directory with the Thunar custom action
cp %n ~/backups/%n

I can modify the filename of the copy to have 'b_' in front with
cp %n ~/backups/b_%n

However, custom actions does not let me add the output of the date command to the file name with
cp %n ~/backups/b_$(date +"%d-%b-%Y_%H:%M")_%n

This action just creates b_[filename].

I've tried a couple of ways to use a bash script in custom actions but haven't succeeded yet. Suggestions very welcome.

Offline

#2 2012-02-05 01:13:02

stqn
Member
Registered: 2010-10-11
Posts: 174

Re: [Solved] Create date-stamped file copy with Thunar custom action

There's nothing special to do to point your custom action to a bash script... The script just has to be executable.

Offline

#3 2012-02-05 02:14:40

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: [Solved] Create date-stamped file copy with Thunar custom action

Hi, stqn. Many thanks for your quick reply.

Each of the scripts I've tried has been executable. In the 'command' box in the custom action dialogue, I've tried entering the path to the script, and also 'xfce4-terminal' followed by the path to the script. Neither works. The script is just the command I posted:

#!/bin/bash
cp %n ~/backups/b_$(date +"%d-%b-%Y_%H:%M")_%n

I suspect the problem might be the expression '%n'. Obviously Thunar understands it, and 'cp' understands it when it's included in a custom action command, but maybe not when it's used in a simple bash script? (Although stat does.)

Offline

#4 2012-02-05 09:37:41

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: [Solved] Create date-stamped file copy with Thunar custom action

Whoops. Of course that script won't work, '%n' is meaningless outside the custom action context.

Still puzzled that I can prefix the copy's filename with any string I like, but not with the unrelated command output from date.

Offline

#5 2012-02-05 14:15:48

stqn
Member
Registered: 2010-10-11
Posts: 174

Re: [Solved] Create date-stamped file copy with Thunar custom action

Something like this should work:

Custom action: /home/refugee/bin/backup.sh "%n"

backup.sh: cp $1 ~/backups/b_$(date +"%d-%b-%Y_%H:%M")_$1

(Not sure if you have to put quotes around %n or not.)

Offline

#6 2012-02-05 20:04:40

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: [Solved] Create date-stamped file copy with Thunar custom action

Many thanks, stqn, worked perfectly. No quotes needed on %n in the custom action command.

I'd tried putting in a placeholder ($0) in the script yesterday, but couldn't get the direction to the script correct in the custom action command.

Offline

#7 2012-02-05 20:28:27

stqn
Member
Registered: 2010-10-11
Posts: 174

Re: [Solved] Create date-stamped file copy with Thunar custom action

Yeah I first tried ~/bin/script but it doesn't work as a custom action. The full path is needed. Glad it's working now!

Offline

#8 2012-02-05 21:58:44

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: [Solved] Create date-stamped file copy with Thunar custom action

Here's a step-by-step explanation for beginners like me!

Why this custom action is useful: When I'm working over several hours or days on a file (text in LibreOffice, spreadsheet in Gnumeric, image in GIMP, etc), I like to keep earlier versions as backups until work on the file is finished. In the past, I would open the file in the relevant application, think of a new name for that current version, save a copy with that name, and then start work on the file. This Thunar method has fewer steps and uses the same, easily understood naming convention for all file versions. It doesn't change the file suffix, as happens with the time-honoured 'save a copy as .bak', so the backups can be opened with the relevant applications from the Thunar GUI.

How to do it (please modify for your preferred file paths, etc):

1) Create a directory in your home directory called 'backups'.
2) Copy this into a text editor:

#!/bin/bash
cp $1 ~/backups/$(date +"%d-%b-%Y_%H:%M:%S")_$1

3) Save this text file as stamper.sh in your home directory.
4) Make it executable in the Thunar GUI by right-clicking on stamper.sh; go to Properties/Permissions and tick the Program box.
5) In Thunar, go to Edit/Configure custom actions...
6) Click the + icon at right to add a new action.
7) On the Basic tab, enter

Name: Make time-stamped copy
Description: -
Command: ~/stamper.sh %n

8) On the Appearance Conditions tab:
File pattern: put here the file suffix types you want to make time-stamped copies of, and separate them with a semicolon, e.g. *.txt;*.odt;*.gnumeric;*.png
Tick all the 'Files' boxes

9) Choose OK and close the custom action dialog box.

Now when you select a file in Thunar that has a suffix you chose in step (8), e.g. 'Important_document.odt', and right-click, you will see the entry 'Make time-stamped copy'. Choose this entry and a copy of the file will appear in your 'backups' directory with the date and time as a prefix, e.g. '6-Feb-2012_11:14:33_Important_document.odt'.

The details of the time stamp can be changed by editing the "%d-%b-%Y_%H:%M:%S" part of stamper.sh. There's a list of the strftime codes on the Xfce date-time plugin page, http://goodies.xfce.org/projects/panel- … ime-plugin.

Last edited by gnome_refugee (2012-02-05 23:47:18)

Offline

#9 2012-07-12 16:44:21

orbspider
Member
Registered: 2012-01-20
Posts: 11
Website

Re: [Solved] Create date-stamped file copy with Thunar custom action

but what if I'd like the copied file to be "mydocument_120712.odt"  like get the time stamp to append the doc name but inside the extension. ?? 

this would be tons more useful as then in backups -say there are over 100 files now- I can easily find all versions of "mydocument" and all of "myconfig" because they will be sorted alphabetically by the doc name and not by the timestamp.

Last edited by orbspider (2012-07-12 16:47:46)

Offline

#10 2012-07-13 10:37:51

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: [Solved] Create date-stamped file copy with Thunar custom action

Hi, orbspider.

Change the script to

#!/bin/bash
cp $1 ~/backups/$1_$(date +"%d-%b-%Y_%H:%M:%S")

You'll now get files appearing in 'backups' with names like

mydocument.odt_13-Jul-2012_20:28:09

Thunar will still recognise this file as an ODT and open it automatically with your default for this file type. Same with any other date-stamped file created by this method from mydocument.odt.

However, you can't use the right-click script method on the date-stamped file mydocument.odt_13-Jul-2012_20:28:09, because Thunar doesn't know what the heck a '.odt_13-Jul-2012_20:28:09' file is.

If you want to make a date-stamped version your working or final mydocument version, just delete the bit after '.odt'. You might find that's easier than deleting the stamp from mydocument_13-Jul-2012_20:28:09.odt!

Offline

#11 2012-07-13 15:49:10

orbspider
Member
Registered: 2012-01-20
Posts: 11
Website

Re: [Solved] Create date-stamped file copy with Thunar custom action

thanks gnome_refugee
I've found out that cp %n %n_1 does all I need because I don't need date-time stamp in particular
but to copy multiple files is more tricky, i've had no success yet

Edit: your file copy with time-stamp is a good idea, now  think about it.

Last edited by orbspider (2012-07-13 19:48:44)

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 562.78 KiB (Peak: 579.63 KiB) ]