• 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: "koenig.yvan" <email@hidden>
  • Date: Sun, 23 Feb 2014 15:28:39 +0100

Oops:
I left typos and a wrong copy/paste
Here is the correct version.

Yvan KOENIG (VALLAURIS, France) dimanche 23 février 2014 15:25:47


Le 23/02/2014 à 14:27, 2551 <email@hidden> a écrit :

To be fair,
On 23 Feb 2014, at 20:18, Nigel Garvey <email@hidden> wrote:
Did Apple really distribute a script containing this abomination?!


To be fair, that script did not come from my own machine so I can’t verify that; it was sent to me a few months back by somoene asking for help to make it work.

The only changes I made to it were to add the comment “—modified for Mavericks” and to swap the order of parameters around.

Whether the script had been modified prior to being sent to me, of course, is always possible (I don’t think my old 2004 iBook will boot anymore, or I’d be tempted to go and check!).

Thanks to your message I borrowed the original scripts from my daughter's iBook.
According to the embedded copyright, they are in fact older than yours.

Here is the Add to File Names one with needed changes.

(*
Add Prefix-Suffix to File Names

This script is designed to add a prefix or suffix to files in the front window of the desktop.
If no folder windows are open, the script will effect items on the desktop.

Copyright © 2001 Apple Computer, 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.

2014/02/23 Yvan KOENIG reenabled the choose folder instruction
and replaced the awful instructions coercing record to string by clean ones.
*)

-- The following line is disabled due to a Menu Manager bug -- no longer needed
set the source_folder to (choose folder with prompt "Pick the folder containing the files 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} # AWFUL INSTRUCTION # was a typo
set {text returned:prefix_or_suffix, button returned:button_pressed} to result # Thanks to Nigel GARVEY
if the button_pressed is "Cancel" then return "user cancelled" # Useful when the hosting system doesn't run in English !
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 false and ¬
alias of this_info is false 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} # AWFUL INSTRUCTION # was a typo
# set {text returned:new_item_name, button returned:button_pressed} to result # Thanks to Nigel GARVEY
if the button_pressed is "Cancel" then return "user cancelled" # Useful when the hosting system doesn't run in English !
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}to result  # AWFUL INSTRUCTION # was a typo and a wrong copy/paste
# set {text returned:new_item_name, button returned:button_pressed} to result # Thanks to Nigel GARVEY
if the button_pressed is "Cancel" then return "user cancelled" # Useful when the hosting system doesn't run in English !
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

Yvan KOENIG (VALLAURIS, France) dimanche 23 février 2014 15:18:20



 _______________________________________________
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>
References: 
 >Re: AppleScripts that I have come to love no longer work (From: Nigel Garvey <email@hidden>)
 >Re: AppleScripts that I have come to love no longer work (From: 2551 <email@hidden>)
 >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