image
image

Go Back   macosx.com > Scripts > Apple Scripts

Reply
 
LinkBack Thread Tools
  #1  
Old March 16th, 2008, 02:17 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,679
Thanks: 6
Thanked 50 Times in 46 Posts
Mikuro will become famous soon enough
[AppleScript] Duplicate files with timestamp

Here's a script I just wrote today. It duplicates the currently selected files in the Finder, and then puts a timestamp in the name of the duplicates (instead of the generic "copy"). The timestamp uses a long date format that is properly sortable as plain text in any program: YYYY-MM-DD hh-mm-ss

For example, if you load the script with "MyFile.txt" selected at 2:15 PM, the duplicate will be named something like "MyFile 2008-03-16 14-15-01.txt".

It works with any number of files and folders selected at once.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

Last edited by Mikuro; March 16th, 2008 at 02:29 PM. Reason: Changed file format from ".script" (compiled) to ".applescript" (text)
Reply With Quote
The Following User Says Thank You to Mikuro For This Useful Post:
gabiton (July 23rd, 2009)
  #2  
Old September 21st, 2008, 10:34 AM
Registered User
 
Join Date: Sep 2008
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
iaeon is on a distinguished road
Hi Mikuro

Could be just what I am looking for, but as a script newbie before I do something horribly wrong can you describe how:
a) to install / use it (applescript editor compile. Run each time one wants to rename a file?) and
b) it works from a user point of view.

Ideally I would love to be able to right-click a file (ctrl-click) and have a 'timestamp duplicate' option.
Reply With Quote
  #3  
Old September 21st, 2008, 11:30 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,679
Thanks: 6
Thanked 50 Times in 46 Posts
Mikuro will become famous soon enough
Hi iaeon.

There are different ways you could install it. I like to use the Script menu. I decided to write a how-to on enabling and using the Script menu, and I just posted it here: Use the AppleScript menu

In short, I have it set up so that I select the file I want to duplicate in the Finder, then choose my script from the Script menu.
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
  #4  
Old September 21st, 2008, 01:07 PM
Registered User
 
Join Date: Sep 2008
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
iaeon is on a distinguished road
Thanks Mikuro - tried it out and works fine. Your script duplicates files and timestamps just as you say.

Only thing - it opens in the script editor and has to be manually run. I don't seem to be able to compile it to an .app so that it just runs when selected fom the scripts menu. I tried opening the .applescript file and doing a compile but that does not work, and I tried opening it in Textmate first and then pasting to the script editor. This approach generates an error on a compile. "Syntax Error - Expected expression but found unknown token". The character it is unhappy with is Â
Reply With Quote
  #5  
Old September 21st, 2008, 02:14 PM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,679
Thanks: 6
Thanked 50 Times in 46 Posts
Mikuro will become famous soon enough
I see. I didn't realize the script menu wouldn't work with plain-text scripts (.applescript files). Do this to convert it:

- Open the file in Script editor.
- Choose File > Save As
- Select "Script" as the File Format and save it.

That will give you a .scpt file that should work.

The reason I posted a .applescript file instead of a .scpt is that .scpts don't seem to work on different computers sometimes.

Or try downloading this .scpt I made. Maybe it'll work.
Attached Files
File Type: zip Duplicate selected files with timestamp.scpt.zip (4.5 KB, 18 views)
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
The Following User Says Thank You to Mikuro For This Useful Post:
iaeon (September 21st, 2008)
  #6  
Old September 21st, 2008, 04:00 PM
Registered User
 
Join Date: Sep 2008
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
iaeon is on a distinguished road
Thanks Mikuro, works fine now, and as I said above just what I have been looking for! - I should probably have figured that one out myself! Funny how when 'somebody available knows better' ones own thinking abilities don't wish to be stretched.
Reply With Quote
  #7  
Old February 20th, 2009, 10:50 PM
Registered User
 
Join Date: Feb 2009
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
ejang is on a distinguished road
Hi, I downloaded a copy of your duplicator script today. It works very well with highlighted files.

As a new user to script editor (I am very asinine with computers), I have not been able to understand very much of the jargon presented in the tutorials. How do I create a script that duplicates itself a number of times? I want to prank a friend of mine- I'm not trying to create a virus.
Reply With Quote
  #8  
Old February 21st, 2009, 09:49 AM
Mikuro's Avatar
Crotchety UI Nitpicker
 
Join Date: Mar 2005
Posts: 2,679
Thanks: 6
Thanked 50 Times in 46 Posts
Mikuro will become famous soon enough
You can get the location of the script file with "the path to me". Then you just need to tell the Finder to duplicate it.
Code:
tell application "Finder"
	repeat with i from 1 to 100
		duplicate (the path to me)
		delay 1
	end repeat
end tell
That'll make 100 copies, pausing for 1 second between each copy.

(Note: If you run this in Script Editor, it might duplicate the Script Editor application. Save your file as an application and run it from the Finder for best results.)
__________________
Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8

Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc
Reply With Quote
Reply

Bookmarks

Tags
applescript, duplicate, finder, script, timestamp

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 06:08 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC1
Copyright 2000-2010 DigitalCrowd, Inc.