Re: AppleScripts that I have come to love no longer work
Re: AppleScripts that I have come to love no longer work
- Subject: Re: AppleScripts that I have come to love no longer work
- From: "koenig.yvan" <email@hidden>
- Date: Mon, 24 Feb 2014 10:50:20 +0100
Le 24/02/2014 à 00:48, John Baltutis <email@hidden> a écrit :
> On 23 Feb 2014, at 20:18, Nigel Garvey <email@hidden>
> wrote:
>>> Did Apple really distribute a script containing this abomination?!
>
> This is what I have on my Snow Leopard machine, under
> /username/Library/Scripts/Finder Scripts/:
>
> -- TRIM FILE NAMES
> -- ©1998 Sal Soghoian, Apple Computer
>
> tell application "Finder"
> activate
>
> repeat
> display dialog "Text to trim from every file name:"default answer ""
> buttons {"Cancel", "Trim Start", "Trim End"}
> copy the result as list to {the text_to_trim, the button_pressed}
> if the text_to_trim is not "" then exit repeat
> end repeat
>
> set the character_count to the number of characters of the text_to_trim
>
> set the source_folder to choose folder with prompt "Folder of files to
> trim:"
>
> if the button_pressed is "Trim Start" then
> set the matching_items_list to (every file of the source_folder whose
> name begins with the text_to_trim) as list
> else
> set the matching_items_list to (every file of the source_folder whose
> name ends with the text_to_trim) as list
> end if
>
> repeat with this_file in the matching_items_list
> set the current_name to name of this_file
> if the button_pressed is "Trim Start" then
> set the new_name to (characters (the character_count + 1) thru -1
> of the current_name) as string
> else
> set the new_name to (characters 1 thru -(the character_count + 1)
> of the current_name) as string
> end if
> my set_file_name(this_file, the new_name)
> end repeat
> end tell
> beep 2
>
> on set_file_name(this_file, new_file_name)
> tell application "Finder"
> activate
> set the parent_container_path to (the container of this_file) as text
> if not(exists file (the parent_container_path & new_file_name)) then
> try
> set the name of this_file to new_file_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, suchas a colon (:)."
> else --the suggested name is too long
> set the error_message to "The name is more than 31
> characters long."
> end if
> beep
> display dialog the error_message default answer new_file_name
> buttons {"Cancel", "Skip", "OK"} default button 3
> copy the result as list to {new_file_name, button_pressed}
> if the button_pressed is "Skip" then return 0
> my set_file_name(this_file, new_file_name)
> end try
> else --the name already exists
> beep
> display dialog "This name is already taken, please rename." default
> answer new_file_name buttons {"Cancel", "Skip", "OK"} default button 3
> copy the result as list to {new_file_name, button_pressed}
> if the button_pressed is "Skip" then return 0
> my set_file_name(this_file, new_file_name)
> end if
> end tell
> end set_file_name
Yes, it contain three awful instructions :
> copy the result as list to {the text_to_trim, the button_pressed}
> copy the result as list to {new_file_name, button_pressed}
> copy the result as list to {new_file_name, button_pressed}
For years Apple explain that relying upon the order of values in a record is bad practice because this order may change.
It's what was done with Mavericks and it's why the original script fails.
Your version doesn't use « tell me to » in front of the display dialog instructions embedded in the tell application "Finder" block.
At this time I don't know why it was introduced in the versions delivered with 10.4.
It guess that it was not for the « call to OSAX functions » problem introduced with 10.6.
Maybe it was just to put the dialogs at front.
Yvan KOENIG (VALLAURIS, France) lundi 24 février 2014 10:50:14
_______________________________________________
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