• 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: Getting a handler to use a value from a different handler?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting a handler to use a value from a different handler?


  • Subject: Re: Getting a handler to use a value from a different handler?
  • From: Brett Conlon/HU/AU/SonyDADC <email@hidden>
  • Date: Wed, 19 Oct 2005 15:24:13 +1000


G'day,

OK, here's what I have.... (remember some of this code is from Apple's "Replace Text In Item Names") Using Chris's code I merged them together. This is working in replacing any word Title with whatever I enter in the prompt. However, with my list of 7 files one of them doesn't have the wortd Title in it (just Cat#.jpg) and it brought up a dialogue for this file saying there was already a file with the name Cat#.jpg. So the script is somehow taking this file and seems to be trying to replace its name with what it already has.

Either the script needs to only return filenames with the word Title in them or ignore files without Title in it.

Here's the code so far:

on run
        set replacement_string to AskTitle()
        ReplaceText(replacement_string)
end run

on AskTitle()
        set d to display dialog "Title:" default answer ""
        set answer to text returned of d
        return answer
end AskTitle

on ReplaceText(replacement_string)
        try
                tell application "Finder" to set the source_folder to folder "PACKSHOTS" as alias
        end try
        set the search_string to "Title"
        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
                -- replace target string using delimiters
                set AppleScript's text item delimiters to the search_string
                set the text_item_list to every text item of the current_name
                set AppleScript's text item delimiters to the replacement_string
                set the new_item_name to the text_item_list as string
                set AppleScript's text item delimiters to ""
                my set_item_name(this_item, new_item_name)
        end repeat
       
        beep 2
end ReplaceText

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:

This email sent to email@hidden

References: 
 >Re: Getting a handler to use a value from a different handler? (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Slow script with long lists
  • Next by Date: Re: Excel Scripting
  • Previous by thread: Re: Getting a handler to use a value from a different handler?
  • Next by thread: Re: Getting a handler to use a value from a different handler?
  • Index(es):
    • Date
    • Thread