FREN

#FF00AA


4 sept. 2009

Timestamped backups in TextWrangler

TextWrangler 3.0 removed the option to hit a File menu command and create a backup of the file you’re editing, replacing it with a global preference of either keeping backups of every single edit you make, or no backup at all.

That’s damn annoying, because I relied on that option as my own primitive CVS, making a backup of a file whenever I was about to make important edits. (Like I said, primitive, I know, but it’s convenient.)

So here’s how you can restore that functionality, using AppleScript. Go to the Scripts menu (the little scroll icon near Help — I think it’s enabled by default?) and select “Open Scripts Folder”; make a copy of an existing script, rename it to something like “00) Make Timestamped Backup.scpt” (the “00)” won’t be displayed, it serves to order the scripts in the menu), double-click the file to open it in Script Editor, and replace its contents with the following:

tell application "TextWrangler"

set fileAlias to (file of document 1 of window 1)set filePath to POSIX path of (fileAlias as text)

end tell

 

tell application "Finder"

set fileName to name of fileAlias

set fileExtension to name extension of fileAlias

set fileBasePath to text 1 thru -((length of fileExtension) + 2) of filePath

 

do shell script "cp " & fileBasePath & "." & fileExtension & " " & fileBasePath & "." & "`date +’%Y-%m-%d.%H-%M-%S’`" & "." & fileExtension

end tell

 

tell application "TextWrangler"

display dialog "Backed up " & fileName & "." buttons {"Ok"} default button 1

end tell

(Make sure you don’t mangle the assortment of double quotes, single quotes and backquotes on that “do shell script” line.)

Now your TextWrangler has a “Make Timestamped Backup” command, ready to use, that will do just that and not ask you any questions; it will just display a confirmation dialog when it’s done. You can also use the Scripts palette (Window menu, Palettes, Scripts) to give it a hotkey.

Vous voulez savoir quand je poste du contenu sur mon blog ? Il suffit de vous inscrire gratuitement à un agrégateur RSS (Feedly, NewsBlur, Inoreader, …) et d'ajouter www.ff00aa.com à vos flux (ou www.garoo.net pour vous abonner à tous les sujets). On n'a pas besoin de newsletters, pas besoin de Twitter, le RSS existe toujours.

Mentions légales : ce blog est hébergé par OVH, 2 rue Kellermann, 59100 Roubaix, France, www.ovhcloud.com.

Les données des visiteurs de ce blog ne sont pas utilisées ni transmises à des tiers. Les posteurs de commentaires peuvent demander leur suppression par e-mail.

Tous contenus © de l'auteur ou couverts par le droit de citation.