• 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
Problems with Mac to PC names conversion script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with Mac to PC names conversion script


  • Subject: Problems with Mac to PC names conversion script
  • From: Brett Conlon <email@hidden>
  • Date: Wed, 17 Oct 2007 09:04:04 +1100


Hi all,

Can anyone suggest a way to improve/fix an issue with the below script where it chokes on files on a Mac Server which are either locked or have incorrect permissions. I'm part way there with detecting the error type with bad permissions but I've had problems actually getting the script to successfully change the permissions on the Mac Server - even if it is a read/write volume.

Here's the script:

#############################################################

(* requires Satimage.osax *)

property myListOfChar : {"/", "\\", "?", "|", "*", "<", ">", "\""} --last entry is for a single quote "
property myReplacementChar : {"-", "-", "X", "_", "_", "_", "_", "'"} --last entry quote replaced by an apostrophe

to open itemlist
        process_items from itemlist
end open

to run
        process_items from navchoose object with prompt ¬
                "Choose folders or files to check/rename:" with multiple files
end run

to process_items from itemlist
        set mainFileList to {}
        set mainFolderList to {}
        set renamedFiles to {}
        set renamedFolders to {}
        tell application "Finder" to repeat with currItem in itemlist
                set currClass to item currItem's class
                if currClass is document file then
                        set mainFileList's end to currItem's contents
                else if currClass is folder then
                        set mainFolderList's end to currItem's contents
                end if
        end repeat
        check_items from mainFileList against renamedFiles
        process_folders from mainFolderList against {renamedFiles, renamedFolders}
        display dialog (results_summary for {renamedFiles, renamedFolders}) buttons "OK" default button 1
end process_items

to check_items from itemlist against renamedList
        tell application "Finder" to repeat with currItem in itemlist
                set currName to currItem's name as Unicode text
                set newname to (change myListOfChar into myReplacementChar in currName) as Unicode text
                if newname is not currName then
                        set renamedList's end to currName
                        try
                                set currItem's name to newname
                        on error number the error_number
                                if the error_number is -48 then --("The operation could not be completed because there is already an item with that name.") the error_message number the error_number
                                        if name extension of currItem is not "" then
                                                set CurrItemExt to name extension of currItem
                                                set ExtNumChars to number of characters of CurrItemExt --determine if 3 or 4 char extension.
                                                set newname to (text 1 thru -(ExtNumChars + 2) of newname) & "-1." & CurrItemExt
                                        else
                                                set newname to (newname & "-2.")
                                        end if
                                        set currItem's name to (newname)
                                else if the error_number is -45 then -- "The operation could not be completed because the file “XXX” is locked."
                                        select currItem
                                        tell me to display dialog "The file selected in the Finder is locked and the script is unable to fix the incorrect characters in its name. Please resolve this file manually when the script is finished (ask the Technical Coordinator for assistance if required)." buttons {"Cancel", "OK"} default button 2
                                else if the error_number is -5000 then -- "The operation could not be completed because you do not have enough access privileges."
                                        select currItem
                                        tell me to display dialog "Due to insufficient privileges the script is unable to fix incorrect characters in the name of the file which is selected in the Finder. Please ask the Technical Coordinator to assist you to resolve this after the script has finished processing.)." buttons {"Cancel", "OK"} default button 2
                                end if
                        end try
                end if
        end repeat
end check_items

to process_folders from mainFolderList against {renamedFiles, renamedFolders}
        tell application "Finder" to repeat with mainFolder in mainFolderList
                set allItems to (a reference to mainFolder's entire contents)
                if (count document files of allItems) > 0 then ¬
                        my (check_items from (get document files of allItems) against renamedFiles)
                set folderCount to count folders of allItems
                if folderCount is 0 then
                        set folderList to {}
                else if folderCount is 1 then
                        set folderList to folders of allItems as alias as list
                else
                        set folderList to folders of allItems as alias list
                end if
                set folderList's end to mainFolder's contents (* optional: include top-level folder *)
                my (check_items from folderList against renamedFolders)
        end repeat
end process_folders

on results_summary for {renamedFiles, renamedFolders}
        set reportFiles to (count renamedFiles) > 0
        set reportFolders to (count renamedFolders) > 0
        if not (reportFiles or reportFolders) then return "No name changes were necessary."
        set msg to "The following names were changed:"
        set tid to text item delimiters
        set text item delimiters to return & tab
        if reportFiles then set msg to msg & return & return & {"Files:", "", ""} & renamedFiles
        if reportFolders then set msg to msg & return & return & {"Folders:", "", ""} & renamedFolders
        set text item delimiters to tid
        msg
end results_summary

#############################################################

I have used the code from the following applet in the past to try and fix the permissions but as I mentioned it would fail at making the changes:

#############################################################

on open (Folderz)
        try
                repeat with thisFolder in Folderz
                        set filePath to quoted form of POSIX path of thisFolder
                        do shell script "chmod -R 777 " & filePath
                end repeat
                display dialog "Permissions changed successfully." buttons {"Thanks!"} default button 1
        on error
                display dialog "Changing permissions failed. Please try it manually" buttons {"OK"} default button 1
        end try
end open

on run
        try
                set aFolder to choose folder with prompt "Please choose a folder to process"
                set filePath to quoted form of POSIX path of aFolder
                do shell script "chmod -R 777 " & filePath
                display dialog "Permissions changed successfully." buttons {"Thanks!"} default button 1
        on error
                display dialog "Changing permissions failed. Please try it manually" buttons {"OK"} default button 1
        end try
end run

#############################################################

Your help is most appreciated!

Cheers,

Brett
 _______________________________________________
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: Problems with Mac to PC names conversion script
      • From: Axel Luttgens <email@hidden>
    • Re: Problems with Mac to PC names conversion script. setuid command on a Mac server
      • From: Levon Spradlin <email@hidden>
  • Prev by Date: AppleScript 2.0?
  • Next by Date: Re: AppleScript 2.0?
  • Previous by thread: Problems with Mac to PC names conversion script
  • Next by thread: Re: Problems with Mac to PC names conversion script. setuid command on a Mac server
  • Index(es):
    • Date
    • Thread