The DAM Forum
Welcome, Guest. Please login or register.
June 19, 2013, 02:13:12 AM

Login with username, password and session length
Search:     Advanced search
Jan 9, 2012
John Beardsworth's new Lightroom site
Lightroom Solutions
27968 Posts in 5116 Topics by 2914 Members
Latest Member: imthedamstar
* Home Help Search Login Register
+  The DAM Forum
|-+  Software Discussions
| |-+  Scripting
| | |-+  AppleScript to add text before "." in filename
« previous next »
Pages: [1] Print
Author Topic: AppleScript to add text before "." in filename  (Read 5370 times)
David Mackie
Jr. Member
**
Posts: 53


View Profile WWW
« on: December 10, 2006, 12:33:53 PM »

I wanted to add " _Orig" to all my original JPGs (only recently started shooting RAW) to conform to the DAM methodology as suggested by Peter in his book.

file names will change from

djm_YYMMDD_idx.jpg   to djm_YYMMDD_idx_Orig.jpg   , where idx is a sequential index (no longer have the original camera index).

I don't have Bridge, GraphicConverter is a bit cumbersome for this (and the cache takes too long), and iView does not handle this type of rename change well.

So I adapted an Apple written Finder script and it is attached.

I run Tiger 10.4.8

David



(*
Add Text String to File Names - just previous to suffix

This script is designed to add a text string just before the . to files in the front window of the desktop.
If no folder windows are open, the script will effect items on the desktop.

This script is provided "AS IS" and the reponsibility for its operation is yours.

This script was modified from Apple sample code buy was modified.

*)


try
   tell application "Finder" to set the source_folder to (folder of the front window) as alias
on error -- no open folder windows
   set the source_folder to path to desktop folder as alias
end try

set the the_new_text to ""
repeat
   display dialog "Enter the text to use:" default answer the the_new_text buttons {"Cancel", "OK"}
   copy the result as list to {the the_new_text, the button_pressed}
   if the the_new_text is not "" then exit repeat
end repeat
set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
   set this_item to item i of the item_list
   set this_item to (source_folder & this_item) as alias
   set this_info to info for this_item
   set the current_name to the name of this_info
   if folder of this_info is false and ¬
      alias of this_info is false then
      if the button_pressed is "OK" then
         set default_delimiters to AppleScript's text item delimiters
         set AppleScript's text item delimiters to {"."}
         set the_root_name to the first text item of the current_name
         set the_suffix_name to the last text item of the current_name
         set the new_file_name to the (the the_root_name & the the_new_text & "." & the the_suffix_name) as string
         set AppleScript's text item delimiters to default_delimiters
      end if
      my set_item_name(this_item, the new_file_name)
   end if
end repeat
beep 2

on set_item_name(this_item, new_item_name)
   tell application "Finder"
      --activate
      set the parent_container_path to (the container of this_item) as text
      if not (exists item (the parent_container_path & new_item_name)) then
         try
            set the name of this_item to new_item_name
         on error the error_message number the error_number
            if the error_number is -59 then
               set the error_message to "This name contains improper characters, such as a colon (Smiley."
            else --the suggested name is too long
               set the error_message to error_message -- "The name is more than 31 characters long."
            end if
            --beep
            tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
            copy the result as list to {new_item_name, button_pressed}
            if the button_pressed is "Skip" then return 0
            my set_item_name(this_item, new_item_name)
         end try
      else --the name already exists
         --beep
         tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
         copy the result as list to {new_item_name, button_pressed}
         if the button_pressed is "Skip" then return 0
         my set_item_name(this_item, new_item_name)
      end if
   end tell
end set_item_name
Logged

David
peterkrogh
Administrator
Hero Member
*****
Posts: 5682


View Profile
« Reply #1 on: December 12, 2006, 10:17:48 PM »

David,
Thanks for posting the script.
WHere do you find iView falling down on this in Batch Rename?  Seems to do this just fine for me.
Peter
Logged
David Mackie
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #2 on: December 15, 2006, 07:00:52 AM »

Peter,
You are correct that it does not fall down. 

First I rename the files as per the DAM book. (eg.  djm_061225_025.jpg) as this takes all 3 naming options in iView Batch Rename (one for djm, one for date, one for the index). Then I have to run Batch Rename again to add the _Orig.

I have saved the two screens so now I run Batch Rename twice using Command+Y.

So I don't use the script anymore!

They should just add the option to have more than 3 options to alter the file in one name. Unless there is another way of combining I have not figured out.

Dave
Logged

David
peterkrogh
Administrator
Hero Member
*****
Posts: 5682


View Profile
« Reply #3 on: December 16, 2006, 01:52:22 PM »

I agree that it does not seem like it would be too hard to just add one or two more criteria.   Have you files a feature request?
Peter
Logged
David Mackie
Jr. Member
**
Posts: 53


View Profile WWW
« Reply #4 on: April 15, 2007, 10:53:12 AM »

Peter
No I have not filed a features request. I guess I should. But then I am shooting mostly in RAW now (except for my point and shoot) and then I don;'t need do worry about adding _Orig.

One thing also about shooting RAW is it makes the whole editing process so much easier and faster. With JPGs I saved the originals, then did my editing in Photoshop on coverted TIFFs. Also at this point I would add some extra keywords I had missed before and then wanted these in my original iView catalogue so I had to sync my catalogues with MetaSync.

Working with a RAW process is much more efficient - fewer steps to get my final product.

David
« Last Edit: April 15, 2007, 10:57:40 AM by David Mackie » Logged

David
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!