• 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
Finder - make new folder solution
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Finder - make new folder solution


  • Subject: Finder - make new folder solution
  • From: Roderick Scott Corporation <email@hidden>
  • Date: Tue, 22 May 2001 23:56:20 -0600

Hello & thanks to all that replied!

I have a working solution which I have attached. It bypasses the problem I encountered with placing folders within the Desktop Folder on any other drive except the startup disk. I've tried a couple of variations but none seem to work around the problem.

I hope this helps [someone else],

Scott

------------------------------------------------------------------------

-- script to ensure a path is valid.
-- Returns the final path to the calling function (important if folders are on desktop)
on sureFolder(strPath)

-- save & modify the text item delimeter to ":" for path manipulation
set oldSpaceChar to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"

-- direct commands to the Finder
tell application "Finder"

activate

-- test to see if the entire path is valid
if folder strPath exists then
-- restore the text item delimeter
set AppleScript's text item delimiters to oldSpaceChar

return strPath

else -- proceed to building the path

-- initialize a variable to hold the root directory initially, then the parent after that...
set strParentFolder to (text item 1 of strPath as string) & ":"

-- loop through the path, verifying the existence of each level
-- Note:We don't want the last field after the final : as it will always be empty and hence the count -1 limit
-- also, the first item is the root directory/volume name so we don't start there.
repeat with i from 2 to ((count (text items in strPath)) - 1)

-- get the name of the folder
set strFolderName to (text item i of strPath) as string

-- extract the sub-path from left to right, adding the final path colon
set strFolderPath to strParentFolder & strFolderName & ":"

-- verify existence of this sub-path and build it if it does not exist
if not (folder strFolderPath exists) then

-- do the deed, make the folder within the last valid folder
make new folder at folder strParentFolder with properties {name:strFolderName}
set strParentFolder to result as string

else

-- update the root path for the next folder if necessary
set strParentFolder to strFolderPath

end if


end repeat
end if

end tell

-- re-activate the script application
activate

-- restore the text item delimeter
set AppleScript's text item delimiters to oldSpaceChar

return strFolderPath

end sureFolder

------------------------------------------------------------------------

________________________________________
Scott Sandeman-Allen
Roderick Scott Corporation
Edmonton, Alberta. Canada


  • Prev by Date: Re: Tell Finder Make New Folder wierdness!
  • Next by Date: Re: Scope of globals, parents and children
  • Previous by thread: Re: Tell Finder Make New Folder wierdness!
  • Next by thread: OSX and Applet permissions
  • Index(es):
    • Date
    • Thread