Re: Making a folder in the user's library
Re: Making a folder in the user's library
- Subject: Re: Making a folder in the user's library
- From: Christopher Nebel <email@hidden>
- Date: Thu, 3 Apr 2003 10:33:28 -0800
On Wednesday, April 2, 2003, at 01:29 PM, John S. Baltutis wrote:
On 3/31/03, Jeffrey Mattox <email@hidden> wrote:
I want to make a folder, "myFolder", in the current user's
Library/Application Support folder, creating the Application Support
folder, if necessary. I know how to script the Finder to make
folders on the desktop, but I'm stuck when working in the library.
I'm having problem dealing with (1) accessing the library folder and
(2) testing for and creating folders several levels deep. How do I
do this?
This works (watch the line wraps):
set listdir1 to do shell script "ls ~/Library" as string
if "Application Support" is not in listdir1 then
do shell script "mkdir ~/Library/'Application Support'" as string
end if
set listdir2 to do shell script "ls ~/Library/'Application Support'"
as string
if "My Folder" is not in listdir2 then
do shell script "mkdir ~/Library/'Application Support'/MyFolder" as
string
end if
You could also do it shorter and more resiliently by using "path to"
and the Finder. "path to" knows about where various special folder
are, and will create them if they don't exist, so you don't need to
know the name "Application Support", nor do you need to know exactly
where it is. (Special folders have been known to move.) Therefore:
set myName to "My Folder"
tell application "Finder"
set appSupport to folder (path to the application support folder from
the user domain)
if exists folder myName of appSupport then
set myFolder to folder myName of appSupport
else
set myFolder to make new folder at appSupport with properties
{name:myName}
end if
-- start filing stuff in myFolder.
end tell
If you insist on using the shell, you could exploit the features that
it has:
do shell script "mkdir -p ~/Library/'Application Support'/'My Folder'"
Using the -p flag will create any intermediate folders in the path, and
won't return an error if the folder already exists.
--Chris Nebel
Apple Development Tools
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.