• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScripts that I have come to love no longer work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScripts that I have come to love no longer work


  • Subject: Re: AppleScripts that I have come to love no longer work
  • From: John Baltutis <email@hidden>
  • Date: Sun, 23 Feb 2014 15:48:33 -0800

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

 _______________________________________________
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


  • Follow-Ups:
    • Re: AppleScripts that I have come to love no longer work
      • From: "koenig.yvan" <email@hidden>
  • Prev by Date: Re: AppleScripts that I have come to love no longer work
  • Next by Date: Re: AppleScripts that I have come to love no longer work
  • Previous by thread: Re: AppleScripts that I have come to love no longer work
  • Next by thread: Re: AppleScripts that I have come to love no longer work
  • Index(es):
    • Date
    • Thread