• 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: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)


  • Subject: Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)
  • From: Laine Lee <email@hidden>
  • Date: Fri, 26 Mar 2010 12:39:27 -0500
  • Thread-topic: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)

Title: Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)

On 3/26/10 12:10 PM, "Robert Poland" <email@hidden> wrote:

> Ed's suggestion gets me past this error, but now I get errors in the next
> section of the script.
>
> This errors at "set the parent_container_path to (container of this_item)"
>
> ERROR: Can't get Container of "Macintosh HD:Users:RLP:Desktop:work
> folder:amer.weihnachten1.jpg".
> NOTE: This still works with older iMac (OS 10.6.2).
>
> --on set_item_name(this_item, new_item_name)
> set this_item to "Macintosh HD:Users:RLP:Desktop:work
> folder:amer.weihnachten1.jpg"
> set new_item_name to "amer.weihnachten1.jpg"
>
> tell application "Finder"
> set the parent_container_path to (container of this_item)
> 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
> end tell
> --end set_item_name
>
>
>
> On Mar 26, 2010, at 10:05 AM, Yvan KOENIG wrote:
>
>> Le 26 mars 2010 à 16:49, email@hidden a écrit :
>>
>>> You could insert this into your script:
>>> tell application "Finder"
>>>   set theKind to class of item (currentItem as text)
>>>   if theKind is folder then set theKind to "folder"
>>> end tell
>>>
>>> In place of:
>>>
>>> set theKind to kind of currentItem
>>
>> Yours and mine return "folder" it the treated item is a folder.
>>
>>> Also, I'd still caution against using index as a variable, it is an
>>> appleScript keyword. In general, if your compiler colors a variable
>>> differently than the other variables in your script, you should pick a
>>> different name for the variable.
>>
>> I definitively agree.
>> This is why, to be free of this kind of problem, I use French_like names for
>> the variables in my own scripts.
>>
>> Yvan KOENIG (VALLAURIS, France) vendredi 26 mars 2010 17:01:36
>
> Robert Poland - Fort Collins, CO
>

OK, Here’s more than you asked for. Save the following script as application. Take a screen shot (if you're screen shots get saved as jpeg's, use a different jpeg if not), and drop it on the application's icon.

on open theitems
    my set_item_name(item 1 of theitems, "Bob's picture.jpg")
end open

on set_item_name(this_item, new_item_name)
    --set this_item to "Macintosh HD:Users:RLP:Desktop:work folder:amer.weihnachten1.jpg"
    --set new_item_name to "amer.weihnachten1.jpg"
    
    tell application "Finder"
        set the parent_container_path to (container of this_item)
        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
    end tell
end set_item_name


BTW, Here’s my folder action that prompts for a new name whenever I take a screen shot.


on adding folder items to this_folder after receiving added_items
   
tell application "Finder"
        
set screenshot_name to (get displayed name of (item 1 of added_items))
    
end tell
   if screenshot_name starts with "screen shot" then
       try
           tell application "Finder"
                
set name_extension to (get name extension of (item 1 of added_items))
                
set the folder_name to the name of this_folder
           
end tell
           set the item_count to the number of items in the added_items
           
set alert_message to "Folder Actions Alert:" & return & return
           
set alert_message to alert_message & "A new screen shot exists in the " & the folder_name & "."
            
repeat
               set the alert_message to (the alert_message & return & return & "You can enter a new name for it if you like..")
                
display dialog the alert_message buttons {"OK", "Cancel"} default button 1 with icon 1 default answer "Enter new name here."
                
set the new_item_name to ((text returned of the result) & "." & name_extension)
                
if the new_item_name contains ":" then
                   display dialog "A file or folder name cannot contain a colon (:), please rename." buttons {"Cancel", "OK"} default button 2
                
else if the new_item_name contains "/" then
                   display dialog "A file or folder name cannot contain a forward slash (/), please rename." buttons {"Cancel", "OK"} default button 2
                
else
                   repeat with i from 1 to (count added_items)
                        
my set_item_name((item i of added_items), new_item_name)
                    
end repeat
                   exit repeat
               end if
           end repeat
       on error ther
           
display dialog ther
       
end try
   end if
end
adding folder items to

on set_item_name(this_item, new_item_name)
    
tell application "Finder"
        
repeat
           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
                   
set the error_message to error_message -- "The name is too long."                    
                   
tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "OK"} default button 3
                    
copy the result as list to {new_item_name, button_pressed}
                    
my set_item_name(this_item, new_item_name)
                
end try
               exit repeat
           else --the name already exists
               
tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "OK"} default button 2
                
copy the result as list to {new_item_name, button_pressed}
                
my set_item_name(this_item, new_item_name)
                
exit repeat
           end if
       end repeat
   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

  • Follow-Ups:
    • Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)
      • From: Yvan KOENIG <email@hidden>
References: 
 >Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609) (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: (no subject)
  • Next by Date: Re: Back and forth between Posix and HFS paths
  • Previous by thread: Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)
  • Next by thread: Re: Rep: old script fails AND BUG in Smile 3.5.2 (build 609)
  • Index(es):
    • Date
    • Thread