• 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: Paul Berkowitz <email@hidden>
  • Date: Thu, 03 Apr 2003 17:52:29 -0800

On 4/3/03 5:31 PM, "John Baltutis" <email@hidden> wrote:

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

'path to' has got absolutely nothing to do with the Finder, and shouldn't be
used in a Finder tell block. (well, back in OS 9, it could lead to trouble.
It may no longer be a problem in OS X.) It's partially 'documented', if you
can call it that, in the Standard Additions dictionary.
>
>> , 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.

That's not what Chris meant. He meant that a later OS revision/upgrade just
might move one of the special folders to a different location than it
presently occupies. If _you_ move it, it's no longer a special folder, just
a regular folder.
>
>> 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

No. that has a bunch of coercions. 'path to' already results in an alias
unless you ask for 'as Unicode text' (or ;as string'). You;'re using the
Finder to coerce it to text then make a folder of it.

Better:

set appSupportPath to (path to application support folder from
user domain as Unicode text)

tell app "Finder" to make new folder at folder appSupportPath with
properties {name:"myFolder"}


[This will also work, but I prefer to use Finder terms like 'folder' in
Finder tell blocks, as above, rather than use aliases. But it will work:

set appSupport to (path to application support folder from
user domain)

tell app "Finder" to make new folder at appSupport with properties
{name:"myFolder"}

]


--
Paul Berkowitz
_______________________________________________
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.

References: 
 >Re: Making a folder in the user's library (From: John Baltutis <email@hidden>)

  • Prev by Date: Re: Making a folder in the user's library
  • 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