Add to Folder Names script broken (and a Thank you!!!)
Add to Folder Names script broken (and a Thank you!!!)
- Subject: Add to Folder Names script broken (and a Thank you!!!)
- From: email@hidden
- Date: Mon, 03 Mar 2014 09:42:49 +0200
Hi
My thanks to all who responded to fix the two applescripts that I use frequently but were broken when put on a 10.9.x machine.
Thank you.
My wife is running a 10.4.x machine and those scripts are on that machine. My guess is that I as I moved upon the world, I dragged them with me.
I did find a person running 10.6.x, copied one of the problem scripts to my mac, and it broke.
So, the suggestion that the scripts that came with 10.6 would work on a 10.9 machine is not 100% true. Some do, some do not.
It is though remarkable that code written in 2001 still runs (for the most part) in 2014.
There was some discussion about the elegance (or lack therefor) of these scripts. My guess is if someone was being paid to rewrite these, they would be more elegant. But, I have not a clue as I am just starting to learn about applescript.
I did try to fix the script below based on what I read but failed miserably. So, I am back, hat in hand, asking for help.
The following script is suppose to add to either the beginning or the end of a batch of folders’ names
When executed, when I press the “prefix” button , it adds “prefix” to the end of the folder's name
When executed when I press the “suffix” button , it adds “suffix” to the end of the folder's name
Might I ask for some assistance in repairing this script please?
And maybe some hints on what to look for when, not if, I find the next problem script...
Thanks
Lee
Turkey
++++++++++++++++++++++++++++++++++++++
(*
Add to Folder Names
This script is designed to add a prefix or suffix to folders in the front window of the desktop.
If no folder windows are open, the script will affect items on the desktop.
Copyright © 2001–2007 Apple Inc.
You may incorporate this Apple sample code into your program(s) without
restriction. This Apple sample code has been provided "AS IS" and the
responsibility for its operation is yours. You are not permitted to
redistribute this Apple sample code as "Apple sample code" after having
made changes. If you're going to redistribute the code, we require
that you make it clear that the code was descended from Apple sample
code, but that you've made changes.
*)
--set the source_folder to (choose folder with prompt "Pick the folder containing the folders to rename:")
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 prefix_or_suffix to ""
repeat
display dialog "Enter the prefix or suffix to use:" default answer the prefix_or_suffix buttons {"Cancel", "Prefix", "Suffix"}
copy the result as list to {the prefix_or_suffix, the button_pressed}
if the prefix_or_suffix 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 true then
if the button_pressed is "Prefix" then
set the new_file_name to the (the prefix_or_suffix & the current_name) as string
else
set the new_file_name to the (the current_name & the prefix_or_suffix) as string
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 (:)."
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
+++++++++++++++++++++++++++++++++++++++++++++++++
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden