• 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: Making a folder in the user's library
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making a folder in the user's library


  • Subject: Re: Making a folder in the user's library
  • From: John Baltutis <email@hidden>
  • Date: Thu, 3 Apr 2003 17:31:15 -0800

On 4/3/03, Christopher Nebel <email@hidden> wrote:
>
> 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 "myFolder" 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,

Neat trick, creating things that don't exist. Where is this capability
documented? I didn't know that and that's why I checked for its existence
using the shell script.

Note that it doesn't work, except for those special folders. When I tried this:

set appSupport to folder (((path to the application support folder from the
user domain) as string) & "myFolder")

I got this error:->"Finder got an error: Can't get folder \"John's JAG
Mac:Users:baltwo:Library:Application Support:myFolder\"."

A bit inconsistent, isn't it? Apparently, it's not tied to the folder call,
but the folder/path to combo. Any more words on how it works?

>, 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.)

But, if you move the Application Support folder onto the desktop and run
the scripts, they will create a new Application Support folder in the users
Library. At least that's what I did to test this little puppy. So, location
might be important (or this may be a bug). If the latter, let me know and
I'll file the appropriate bug.

> Therefore:
>
> set myName to "myFolder"
> tell application "Finder"
> set appSupport to folder (path to the application support folder
>from the user domain)

The following two aren't necessary, he didn't need to check existence of
myFolder, just create it.

> 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:

I don't insist-I was just having problems getting the syntax correct for
the make new folder command, especially with folder names that have spaces
in them. So I fell back on what I knew about formatting the name with the
mkdir command.

>
> 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.

Another neat tidbit-learning to read and comprehend man pages is right up
there with reading AS dictionaries. Thanks for the explanation. A bit of
experimenting results in this revision:

tell application "Finder"
set appSupport to folder (path to the application support folder from
the user domain)
make new folder at appSupport with properties {name:"myFolder"}
end tell

Cheers and thanks for the insights.
_______________________________________________
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.

  • Follow-Ups:
    • Re: Making a folder in the user's library
      • From: Christopher Nebel <email@hidden>
    • Re: Making a folder in the user's library
      • From: Reinhold Penner <email@hidden>
    • Re: Making a folder in the user's library
      • From: Paul Berkowitz <email@hidden>
  • Prev by Date: Re: Apropos of nothing
  • Next by Date: Re: Making a folder in the user's library
  • Previous by thread: Re: Making a folder in the user's library
  • Next by thread: Re: Making a folder in the user's library
  • Index(es):
    • Date
    • Thread